Typescript and Type Definition Gotchas

  1. For JS libraries being consumed in TS, you need to download the type definitions of the JS library else the Intellisense won’t work and TS build will fail.
  2. For NodeJS apps, using require won’t work as TS doesn’t understand it, so you’ll have to install Type Definitions for NodeJS using npm install @types/node -D 
  3. For intellisense to work for third party modules like lodash after having their types installed using npm install @types/lodash -D, use ES 6 import statement instead of require in your TS NodeJS apps
  4. Some libraries like angular and firebase come with the type definitions out of the box, and so for these you don’t need to install @types/<library> to use the library in ts project and to have intellisense working

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s