Skip to content

TS type declarations

third party JS libraries

  • for libraries written in javascript, typescript can not tell their types, so you need to tell typescript about them.
  • library @types provide type definitions (.d.ts files) for js libraries.

TypeScript third party libraries

  • @types: contains ts declarations for js libraries.
  • class-transformer: convert json to the corresponding classes.
  • class-validator: validate the classes.

declare a variable

  • for global variables, that you are sure they will be available at run time, you can use declare var statement.
  • with declare, you don’t give the variable any value, instead you just declare its type.
declare var jQuery: any; // jQuery is a global variable, and tsc won't complain about it.
declare var global: any; // global is a global variable, and tsc won't complain about it.