Skip to content

Using javascript with relaxed typescript

Hostfurl sample templates and modules include typescript, which adds syntax to Javascript for types.

Typescript in Hostfurl code is enabled at high strictness level for Astro code samples. However it can be easily turned down to try changes.

This includes allowing plain .js javascript files to be used

Typescript can get in the way when you want to try changes, are not familiar with how typescript works and want to use javascript in .astro files as well as .js and .jsx files. Hence you might like to avoid using typescript.

Relaxing typescript and using javascript files

To use .js files and relax typescript checks:

  1. In tsconfig.json change "extends": "astro/tsconfigs/strictest", to "extends": "astro/tsconfigs/base"
  2. In package.json change "build": "astro check && astro build", to "build": "astro build",

You can also optionally remove npm typescript package with npm rm typescript or with pnpm rm typescript.

This will not necessarily remove all reported information, warnings and errors in an editor. However the reports should not prevent your code from building and running, if it can.

Turning off typescript reports for a file

Adding //@ts-nocheck to top of a file will turn off typescript information, warning and error reports.