Starting from TypeScript 2.3 you can not only use the type checking and error reporting features of TypeScript in your .ts files but also in your .js files as well.
This new feature is an opt-in option that can be enabled by adding the --checkJs flag. this will enable type checking for all .js files by default. Open your tsconfig.json file and add the following line “checkJs”:true :
If you now create a JavaScript file and introduce a type checking error, you’ll get a nice error message from the TypeScript transpiler;
By default setting this flag will enable this feature for all your .js files. It is still possible to selective include/exclude specific files/lines by using any of the following comments;
- Use
// @ts-checkto enable type checking for a single file. - Use
// @ts-nocheckto disable type checking for a single file. - Use
// @ts-ignoreto disable type checking for a single line.