Skip to content

Cannot use custom definitions in TS2 #11383

@jjmoorhouse

Description

@jjmoorhouse

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    DuplicateAn existing issue was already created

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions