Skip to content
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

Cannot use custom definitions in TS2 #11383

Closed
jjmoorhouse opened this issue Oct 5, 2016 · 4 comments
Closed

Cannot use custom definitions in TS2 #11383

jjmoorhouse opened this issue Oct 5, 2016 · 4 comments
Labels
Duplicate An existing issue was already created

Comments

@jjmoorhouse
Copy link

TypeScript Version: 2.0.3 from npm

Code

I've got the following project structure setup

@types/
-- events
---- index.d.ts
node_modules/
-- @types
-----react, react-dom etc
utils/
-- eventEmitter.js
tsconfig.json

In my tsconfig.json I have:

{
  "compilerOptions": {
    "module": "commonjs",
    "moduleResolution": "node",
    "target": "es5",
    "jsx": "react",
    "allowJs": true,
    "sourceMap": true,
    "typeRoots" : [
      "./@types"
    ],
    "types" : [
      "events",
      "ajax",
      "path",
      "keymirror"
    ]
  },
  "exclude" : [
    "node_modules",
    "@types"
  ]
}

in eventEmitter.js I have the following:

import * as events from "events";

Actual Behaviour:
When I try and compile with the file structure above, I get the following error

ERROR in ./utils/eventEmitter.ts
(1,25): error TS2307: Cannot find module 'events'.

However, if I move ./@types/events/index.d.ts to ./node_modules/@types/events/index.d.ts everything works as expected and the eventEmitter will compile

Expected behaviour:
Using the above configuration I would expect the compiler to pick up on my custom definitions which are in ./@types in the same way it does when the same definitions are in the node_modules/@types folder

@tapvolt
Copy link

tapvolt commented Oct 7, 2016

I'm having the same problem too.

@mhegazy
Copy link
Contributor

mhegazy commented Oct 12, 2016

This looks like #11137. it should be fixed in the next release. for now to work around this issue, you will need to add a path mapping entry to tell the compiler to look in the @types override folder as such:

{
  "compilerOptions": {
    ...
    "path": {
         "*": ["*", "./@types/*"]
     }
     ...
  }
}

@mhegazy mhegazy added the Duplicate An existing issue was already created label Oct 12, 2016
@jjmoorhouse
Copy link
Author

worked a treat, thankyou very much :)

@mhegazy
Copy link
Contributor

mhegazy commented Oct 13, 2016

closing in favor of #11137

@mhegazy mhegazy closed this as completed Oct 13, 2016
@microsoft microsoft locked and limited conversation to collaborators Jun 19, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Duplicate An existing issue was already created
Projects
None yet
Development

No branches or pull requests

3 participants