Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Referencing TypeScript Type Definitions

I'm building an Aurelia app in TypeScript that utilizes SystemJS/jspm and the TypeScript definition manager. I have .ts source files under /app/** and .d.ts files under /typings/** and /jspm_packages/** (As some definition files are being shipped via jspm).

Obviously the TypeScript compiler doesn't understand SystemJS/jspm or TSD so I need to somehow reference the type definitions managed by them. I've tried passing all .ts files to the compiler so it references both the source and definitions but this leads to a rabbit hole of having to download all the type definitions imported by all the type definitions. It ends up being type definition inception (Yo dawg I heard you like type definitions). Seems that the compiler should only care about things exported by type definitions directly referenced by the source (and not things imported by those definitions).

Anyways, I get the feeling I'm going about this the wrong way and am wondering if there is a better/right way to reference definition files.

PS: Looks like there may be some solutions out there that involve editors/plugins but I'm looking for a strictly CLI approach as this is part of an automated build.

like image 598
hcoverlambda Avatar asked Sep 08 '15 16:09

hcoverlambda


1 Answers

I hate referencing files. What I do is I just use the "excludes" option in tsconfig.json. This guarantees that all typings files will be included in my entire project and I won't ever have to use any <reference>.

Just use the following tsconfig and you should be good to go:

{
  "compilerOptions": {
    "target": "es5", // or es6
    "module": "system",
    "sourceMap": true,
    "declaration": true
  },
  "exclude": [
    "node_modules"
  ]
}

Here's my main file in that module. Notice that there're no references to any declaration file.

like image 75
Louay Alakkad Avatar answered Sep 20 '22 22:09

Louay Alakkad