Skip to content

typeRoots is not working? #12222

@vvakame

Description

@vvakame

I want to try to use @types like repository.

TypeScript Version: Version 2.2.0-dev.20161114

Code

$ tree
tree
.
├── package.json
├── src
│   └── index.ts
├── tsconfig.json
└── typings
    └── foo
        └── index.d.ts

$ cat tsconfig.json
{
    "compilerOptions": {
        "module": "commonjs",
        "target": "es5",
        "typeRoots": [
            "./typings"
        ],
        "types": [
            "foo"
        ],
        "noImplicitAny": false,
        "sourceMap": false
    },
    "include": [
        "src/**/*.ts"
    ]
}

$ cat typings/foo/index.d.ts
export function hi(): void;

$ cat src/index.ts
import * as _ from "foo";
$ tsc -p ./tsconfig.json --traceResolution
======== Resolving module 'foo' from '/***/work/src/index.ts'. ========
Module resolution kind is not specified, using 'NodeJs'.
Loading module 'foo' from 'node_modules' folder.
File '/***/word/src/node_modules/foo.ts' does not exist.

...omit...

File '/node_modules/foo/index.jsx' does not exist.
======== Module name 'foo' was not resolved. ========
======== Resolving type reference directive 'foo', containing file '/***/work/__inferred type names__.ts', root directory '/***/work/typings'. ========
Resolving with primary search path '/***/work/typings'
File '/***/work/typings/foo/package.json' does not exist.
File '/***/work/typings/foo/index.d.ts' exist - use it as a name resolution result.
Resolving real path for '/***/work/typings/foo/index.d.ts', result '/***/work/typings/foo/index.d.ts'
======== Type reference directive 'foo' was successfully resolved to '/***/work/typings/foo/index.d.ts', primary: true. ========
src/index.ts(1,20): error TS2307: Cannot find module 'foo'.

tsc can find typings/foo/index.d.ts , but compile was failed...

Expected behavior:

compile successful.

I expect "typeRoots": [] and "typeRoots: ["./node_modules/@types/"]" are equivalent.
I hope I want to use "typeRoots: ["./node_modules/@types/", "./typings/"]"

Actual behavior:

compile failure.

I read wiki, handbook.
related? #11329 #11137

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