DoubleDebug logo

Reason #2 why I love Typescript:

Global types

Did you know you can access Typescript types from other files without importing them?


Besides the regular .ts files, the Typescript programming language also has support for .d.ts files.

These are called DTS Modules, where D stands for declaration.


DTS files are used to:

  • declare types
  • declare interfaces
  • declare function signatures
  • give Typescript information about some Javascript API

1type Circle = { 2 radius: number; 3 color: string; 4} 5 6function getCircleArea(circle: Circle): number; 7function getCircleCirumference(circle: Circle): number; 8 9const PI: number;

💡 You can also find .d.ts files in NPM modules that were initially written in Javascript. Instead of re-writing these libraries in Typescript, the maintaineres often write .d.ts files to provide developers the information they need to know about their API.

HomeProjectsEducationBlogContactBack to top

© 2022 Double Debug. All rights reserved.

GithubYouTubeTwitter