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

typeRoots is not working? #12222

Closed
vvakame opened this issue Nov 14, 2016 · 2 comments
Closed

typeRoots is not working? #12222

vvakame opened this issue Nov 14, 2016 · 2 comments
Labels
Duplicate An existing issue was already created

Comments

@vvakame
Copy link
Contributor

vvakame commented Nov 14, 2016

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

@mhegazy
Copy link
Contributor

mhegazy commented Nov 14, 2016

this is a duplicate of #11137

typeRoots are only used to resolve /// <reference types=".." /> directives. if you want to import it, then just use baseUrl or add a path mapping entry. you do not need typeRoots in this case.

@mhegazy mhegazy added the Duplicate An existing issue was already created label Nov 14, 2016
@vvakame vvakame closed this as completed Nov 16, 2016
@vvakame
Copy link
Contributor Author

vvakame commented Nov 16, 2016

thank you for your advice!
I am glad that the documentation is more detailed.

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

2 participants