Skip to content

Common TypeScript Gotchas

Max Krieger edited this page Dec 22, 2018 · 6 revisions

Adding npm modules

This might be the most difficult process in TypeScript. If the module doesn't already contain type definitions, someone probably wrote them in the DefinitelyTyped repository (the types for my-module might be available if you npm install @types/my-module).

If you still run into errors with importing afterwards (or if a DefinitelyTyped module doesn't exist), add the following line to your index.d.ts:

declare module "my-other-module";

If necessary, restart the hot reloading process (ctrl-c and then npm start again).

npm module has no default export

Instead of using import myModule from "my-module, try import * as myModule from "my-module".

Adding files (invalid source file error)

If you get a TypeScript compilation error after adding a new file and you have no idea why, restarting the hot reloading process usually works.

Clone this wiki locally