Skip to content

Include node_module of containing folders in the automatic @types discovery #10617

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
mhegazy opened this issue Aug 30, 2016 · 1 comment
Closed
Labels
Bug A bug in TypeScript Fixed A PR has been merged for this issue

Comments

@mhegazy
Copy link
Contributor

mhegazy commented Aug 30, 2016

c:\test>tree /f
│   package.json
│
├───node_modules
│   └───@types
│       └───node
│
└───src
        index.ts
        tsconfig.json

c:\test>cd src

c:\test\src>type index.ts
import * as fs from "fs";

c:\test\src>npm install @types/node
test@1.0.0 c:\test
`-- @types/node@6.0.38

c:\test\src>tsc
index.ts(1,21): error TS2307: Cannot find module 'fs'.

The issue here is that we only including node_modules in the current folder for automatic type discovery. this causes a lot of confusion for users trying to use the new @types package, specially if they are global. ppl do not usually associate the location of their tsconfig.json with it not working, all they see is that sometimes it does and sometimes it does not.

@yortus
Copy link
Contributor

yortus commented Aug 31, 2016

Worth noting that TypeScript already searches up through containing folders for typings that are bundled into their modules, i.e. modules whose package.json uses the "typings" field.

And of course the runtime behaviour with node_modules is to search up through containing folders too.

For example the following very similar example works. The difference is that the @cycle/dom module bundles its own typings. In this case TypeScript does search containing directories.

c:\test>tree /f
│   package.json
│
├───node_modules
│   └───@cycle
│       └───dom
│
└───src
        index.ts
        tsconfig.json

c:\test>cd src

c:\test\src>type index.ts
import * as dom from "@cycle/dom";

c:\test\src>npm install @cycle/dom xstream
test@1.0.0 c:\test
+-- @cycle/dom@12.2.2
`-- xstream@6.2.0

c:\test\src>tsc

@ghost ghost closed this as completed in #10670 Sep 2, 2016
@mhegazy mhegazy added the Fixed A PR has been merged for this issue label Sep 2, 2016
@microsoft microsoft locked and limited conversation to collaborators Jun 19, 2018
This issue was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Bug A bug in TypeScript Fixed A PR has been merged for this issue
Projects
None yet
Development

No branches or pull requests

2 participants