0% found this document useful (0 votes)
19 views1 page

Integrating JavaScript with TypeScript

To integrate JavaScript in a TypeScript project, the allowJs setting must be enabled in tsconfig, while type checking can be activated with checkJs. For large migrations, it's easier to disable checkJs and use // @ts-check on individual files. Type information can be described using JSDoc or type definition files, which are often provided by third-party libraries or available from the Definitely Typed repository.

Uploaded by

mfeticode
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
19 views1 page

Integrating JavaScript with TypeScript

To integrate JavaScript in a TypeScript project, the allowJs setting must be enabled in tsconfig, while type checking can be activated with checkJs. For large migrations, it's easier to disable checkJs and use // @ts-check on individual files. Type information can be described using JSDoc or type definition files, which are often provided by third-party libraries or available from the Definitely Typed repository.

Uploaded by

mfeticode
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Integration with JavaScript 1

Integration with JavaScript

Summary
• To include JavaScript code in a TypeScript project, we need to enable the allowJs setting
in tsconfig.

• JavaScript code included in TypeScript projects is not type-checked by default.

• We can enable type checking by enabling the checkJs setting in tsconfig.

• We can optionally turn off compiler errors on a file-by-file basis by applying // @ts-
nocheck once on top of JavaScript files.

• When migrating a large JavaScript project to TypeScript, we might face numerous


errors. In such cases, it’s easier to disable checkJs and apply // @ts-check (the
opposite of @ts-nocheck) on individual files to migrate them one by one.

• We have two ways to describe type information for JavaScript code: using JSDoc and
declaration (type definition files).

• Type definition files are similar to header files in C. They describe the features of a
module.

• We don’t need to create type definition files for third-party JavaScript libraries. We can
use type definition files from the Definitely Typed GitHub repository (@types/
<package>).

• Newer JavaScript libraries come with type definition files. So there’s no need to install
type definition files separately.

Copyright 2022 Code with Mosh [Link]

You might also like