You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Declaration files in parent directories should not be included when excluded #11363
project
- public (client stuff)
- scripts
- typings (declaration files installed by typings)
- tsconfig.json (client project)
- server
- tsconfig.json (server project)
- node_modules (contains some @types to be used by server project)
Expected behavior:
When compiling client project, which is under public/scripts directory, only files under public/scripts directory should be compiled and referenced.
Actual behavior:
Declaration files in node_modules/@types are referenced, causing compilation errors. The project itself is specified to use "amd" module system.
Adding following to tsconfig.json doesn't help
../../node_modules/@types/express/index.d.ts(16,30): error TS2307: Cannot find module 'serve-static'.
../../node_modules/@types/node/index.d.ts(73,13): error TS2403: Subsequent variable declarations must have the same type. Variable 'require' must be of type 'Require', but here has type 'NodeRequire'.
../../node_modules/@types/passport/index.d.ts(28,30): error TS2307: Cannot find module 'express'.
../../node_modules/@types/serve-static/index.d.ts(16,20): error TS2307: Cannot find module 'mime'.
The issue only happens when compiling a project. Compiling files directly works fine, e.g. tsc -t es5 -m amd --jsx react --sourceMap main.ts
changed the title [-]Declaration files in parent directories should not be included[/-][+]Declaration files in parent directories should not be included when excluded[/+]on Oct 4, 2016
Also, declaration files under public/scripts/typings are not used, unless I explicitly add /// <reference path="../typings/index.d.ts" /> to source files.
I've run into this issue a number of times and I would really like to see a fix for it. Unfortunately there's some argument I believe as to whether or not it's a bug or a feature.
The reason the exclude doesn't work is because it's designed to work around the problem that while one (usually) does not want to compile TypeScript downloaded as part of external packages, one often wants their definitions, and this is essential for Types (@types). The broader issue is that the language service mimics the node module resolution algorithm. This performs a recursive walk up the directory tree looking for declaration files specifically in folders named node_modules/x and node_modules/@types/x where x is the exact string name of the imported dependency.
This behavior is not amenable to RequireJS and SystemJS loaders and environments. Is also completely unhelpful for those using a package manager other than npm to manage their client sids dependencies.
That said, this is not the reason why reason the declarations in your typings folder are not being picked up. You can specify "compilerOptions.typeRoots": ["./typings"] but it depends on additional factors. Posting your full tsconfig file would be helpful.
cnshenj my apologies it looks like there's a specific answer to solve your specific problem.
Set "compilerOptions.types": [] see #11257.
Sorry for the rant
If "types" is defined in tsconfig.json or --types is passed on the commandline, no automatic type inclusion is triggered. if you do not like what the compiler loads by default specify "types": [...] in you tsconfig.json.
Activity
[-]Declaration files in parent directories should not be included[/-][+]Declaration files in parent directories should not be included when excluded[/+]cnshenj commentedon Oct 4, 2016
Also, declaration files under
public/scripts/typingsare not used, unless I explicitly add/// <reference path="../typings/index.d.ts" />to source files.aluanhaddad commentedon Oct 4, 2016
I've run into this issue a number of times and I would really like to see a fix for it. Unfortunately there's some argument I believe as to whether or not it's a bug or a feature.
aluanhaddad commentedon Oct 4, 2016
The reason the exclude doesn't work is because it's designed to work around the problem that while one (usually) does not want to compile TypeScript downloaded as part of external packages, one often wants their definitions, and this is essential for Types (@types). The broader issue is that the language service mimics the node module resolution algorithm. This performs a recursive walk up the directory tree looking for declaration files specifically in folders named
node_modules/xandnode_modules/@types/xwherexis the exact string name of the imported dependency.This behavior is not amenable to RequireJS and SystemJS loaders and environments. Is also completely unhelpful for those using a package manager other than npm to manage their client sids dependencies.
That said, this is not the reason why reason the declarations in your typings folder are not being picked up. You can specify
"compilerOptions.typeRoots": ["./typings"]but it depends on additional factors. Posting your full tsconfig file would be helpful.aluanhaddad commentedon Oct 4, 2016
cnshenj my apologies it looks like there's a specific answer to solve your specific problem.
Set
"compilerOptions.types": []see #11257.Sorry for the rant
mhegazy commentedon Oct 4, 2016
If
"types"is defined in tsconfig.json or--typesis passed on the commandline, no automatic type inclusion is triggered. if you do not like what the compiler loads by default specify"types": [...]in you tsconfig.json.cnshenj commentedon Oct 4, 2016
types: []does excludenode_modulesas expected. But how do I include thetypingsdirectory in module resolution?I tried
typeRoots: ["./typings"]but the compiler then looks for a "globals" name.mhegazy commentedon Oct 4, 2016
i am not sure i understand the question. why including
typings\index.d.tsin your project is not sufficient?cnshenj commentedon Oct 4, 2016
Sorry I misunderstood. Yes,
types: []is the solution.