Integration with JavaScript 1
Integration with JavaScript
Summary
• To include JavaScript code in a TypeScript project, we need to enable the allowJs setting
in tscon g.
• JavaScript code included in TypeScript projects is not type-checked by default.
• We can enable type checking by enabling the checkJs setting in tscon g.
• We can optionally turn off compiler errors on a le-by- le basis by applying // @ts-
nocheck once on top of JavaScript les.
• 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 les to migrate them one by one.
• We have two ways to describe type information for JavaScript code: using JSDoc and
declaration (type de nition les).
• Type de nition les are similar to header les in C. They describe the features of a
module.
• We don’t need to create type de nition les for third-party JavaScript libraries. We can
use type de nition les from the De nitely Typed GitHub repository (@types/
<package>).
• Newer JavaScript libraries come with type de nition les. So there’s no need to install
type de nition les separately.
Copyright 2022 Code with Mosh [Link]
fi
fi
fi
fi
fi
fi
fi
fi
fi
fi
fi
fi
fi
fi
fi
fi
fi
fi
fi
fi