Skip to content

incorrect compilation failure because tsc loads node_modules/@types/**/*.d.ts irrespective of their usage.  #11949

Closed
@reshadi

Description

@reshadi

Hi,

TypeScript Version: 2.0.6

Code

a.ts contains:
console.log(1);

run these commands:
npm install supertest @types/supertest
tsc --module commonjs --target es5 --listFiles a.ts

Expected behavior:

a.ts

Actual behavior:

node_modules/@types/superagent/index.d.ts(83,31): error TS2304: Cannot find name 'Promise'.
%AppData%/npm/node_modules/typescript/lib/lib.d.ts
a.ts
C:/types-bug/node_modules/@types/node/index.d.ts
C:/types-bug/node_modules/@types/superagent/index.d.ts
C:/types-bug/node_modules/@types/supertest/index.d.ts

** Problem **
It looks like the tsc compiler loads node_modules/@types/* */ *.d.ts irrespective of their usage.

I thought that in the node module resolution mode, the behavior of the compiler should be to look for .ts or .d.ts files first in the "node_modules/X" then in the "node_modules/@types/X" only when it sees an "import 'X'" in the code. Instead it looks like tsc loads everything in node_modules/@types first.

One use case that this causes problem is when you have both server and client side code and want to compile the server side to es6 and client to es5.

Thanks.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Working as IntendedThe behavior described is the intended behavior; this is not a bug

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions