frankwallis / plugin-typescript

TypeScript loader for SystemJS
MIT License
248 stars 47 forks source link

"Cannot find type definition file" using @types type definitions #145

Closed bmayen closed 8 years ago

bmayen commented 8 years ago

Using typescript@beta. My tsconfig.json has "types": ["jquery"] and I have installed @types/jquery under both node_modules and jspm_packages (as part of my debugging effort). When I build my project I get the following error: "Cannot find type definition file for 'jquery'. (TS2688)"

I have tried other packages as well, but none are found.

frankwallis commented 8 years ago

Thanks for raising this, it is not implemented yet, I need to read up on this feature and figure out how it will work in plugin-typescript.

fchiumeo commented 8 years ago

I use typescript@beta and works

tsconfig.json

{
    "compilerOptions": {
        "target": "es5",
        "module": "system",
        "moduleResolution": "node",
        "sourceMap": false,
        "inlineSourceMap": false,
        "experimentalDecorators": true,
        "emitDecoratorMetadata": true,
        "types": [ "core-js", "jasmine" ]
    },
    "exclude": [
        "node_modules"
    ]
}

systemjs.config.js

        typescriptOptions: {
                tsconfig: true,
                types: []
            }

@frankwallis @types/ replace typings config,no more typings.json or typings install The Future of Declaration Files

bmayen commented 8 years ago

What version of the plugin and JSPM are you using? And where did you install the types; under jspm_packages or node_modules?

fchiumeo commented 8 years ago

"systemjs": "0.19.32" "systemjs-builder": "0.15.23" "plugin-typescript": "5.0.1"

all installed in node_modules, not using jspm packages

bmayen commented 8 years ago

Interesting. I'm on systemjs@0.19.31, but that doesn't seem likely to be the issue.

Latest version of the plugin though. Any chance you could update the plugin to verify if it still works at latest?

If so, the only difference I see is that I'm using JSPM. @guybedford, do you have any insight as to why this might not work using JSPM?

dballesteros7 commented 8 years ago

@fchiumeo Are you sure it is working? I think your types: [] is overriding the first one and nullifying the load of the type declarations.

@frankwallis I took a look into this and the blocking point is that the compiler host in plugin-typescript doesn't provide the files that Typescript is looking for.

Installing to jspm_packages does not seem possible because Typescript search for things like jspm_packages/@types/package_name without the added @version_number.

When using node_modules the problem is that Typescript starts looking for http://localhost:xxx/node_modules/angular/package.json and index.d.ts in the Host files but on the first transpile call the host files only contain the main file.

I wonder if the plugin could do a scan of all files under typeRoots, similar to what Typescript does in: https://github.com/Microsoft/TypeScript/blob/v2.0.0-beta/src/compiler/program.ts#L1058 and make those files available in the compiler host for when typescript requests them.

I would love to help out with this but my knowledge is so far a couple of hours of debugging and reading the source code so I don't know what's the best way to address it.

aindlq commented 8 years ago

@dballesteros7 is right, it can't work with current implementation of plugin-typescript. At least it shouldn't....

Actually, most of the time, in tsc one does not need to provide explicit types in tsconfig. There is additional property typeRoots which has some defaults for node_modules/@types

Looks like ts expose speciall method ts.resolveTypeReferenceDirective which one can use to properly resolve @types, maybe it can be used in host's resolveModuleNames function. This method depends on other host functions like getSourceFile, fileExists, etc.

I'm not really familiar with typescript API, but that is what I found looking around.

Also I've found few existing bugs related to type resolution, e.g: https://github.com/Microsoft/TypeScript/issues/9831

For more details see https://github.com/Microsoft/TypeScript/issues/9184

frankwallis commented 8 years ago

I have implemented some basic support for the types configuration option in 5.0.18. It is now used in the react and angular1 example projects. Also there is some information on the readme: https://github.com/frankwallis/plugin-typescript/blob/master/README.md#types-types-support

Let me know if you find any issues, thanks

tamird commented 8 years ago

This seems to look for the typings in the wrong place:

jspm bundle-sfx app/app build/app.js
     Building the single-file sfx bundle for app/app...

err  Error on fetch for npm:@types/react-dom@0.14.15.js/index.d.ts!github:frankwallis/plugin-typescript@5.0.18/plugin.js at file:///Users/tamird/src/go/src/github.com/cockroachdb/cockroach/ui/jspm_packages/npm/@types/react-dom@0.14.15.js/index.d.ts!file:///Users/tamird/src/go/src/github.com/cockroachdb/cockroach/ui/jspm_packages/github/frankwallis/plugin-typescript@5.0.18/plugin.js
    Loading app/app.tsx
    Error: ENOENT: no such file or directory, open '/Users/tamird/src/go/src/github.com/cockroachdb/cockroach/ui/jspm_packages/npm/@types/react-dom@0.14.15.js/index.d.ts'

Note that .js suffix on the directory name - this suffix is not present on disk.

frankwallis commented 8 years ago

I think this is caused by jspm@0.16 and the defaultJsExtensions behaviour. I am not able to recreate in the react example project using jspm@0.17-beta. I have added a patch in 5.0.19 which I hope will fix this.