Closed
Description
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.