-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Problems using types installed in node_modules/@types #9725
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
Comments
same for me with
With DefinitelyTyped classic (master branch) For example for fs module i have import like import * as fs from 'fs'; For require and global i have no imports. For It will work with import 'mocha' but current definitions works without import |
I'm having a similar problem with My first attempt looked like this: import * as angular from "angular";
let foo:angular.route.IRouteProvider; which gives the following error: I've tried the following variations, all of which complain of various errors. import * as angular from "angular";
import "angular/angular-route";
let foo:angular.route.IRouteProvider;
import * as angular from "angular/angular-route";
let foo:angular.route.IRouteProvider;
I'm sure that I'm doing something wrong, but I can't seem to figure out what. |
With DefinitelyTyped/DefinitelyTyped#10170, you should be able to do: import * as angular from 'angular';
import 'angular-cookies';
let cookiesService: angular.cookies.ICookiesService; or /// <reference types="angular" />
/// <reference types="angular-cookies" />
let cookiesService: ng.cookies.ICookiesService; |
That only resolves the issue with angular specifically. Are you to suggest that for each package with this issue, we must submit PRs which break out the declarations? |
For {
"compilerOptions": {
"types" : [ "node" ]
}
} breaking it up is not an option here since these are really some magical modules that node injects into the module space. |
This is closed, but what is the solution?
|
We have republiushed the angular packages, these should work as intended now.
I am not sure i understand the issue with mocha. it should just work, all you need is |
I should add. my statement above assumes that your if however, your {
"compilerOptions": {
"typeRoots": [
"../node_modules/@types"
]
}
} for a file layout as:
In case you want to say "Do not include all {
"compilerOptions": {
"types": [
"node", "mocha"
]
}
} this will only include hope this helps. |
Sorry, I'm narrowing it down and I think the issue is not on TypeScript. It seems to be on VSCode and ts-loader, I think neither support this new @types folder. I don't know if it is just me or if other people are running in the same issue. I will try this |
can you share your project, or your tsconfig.json |
Structure
tsconfig.json {
"compilerOptions": {
"module": "commonjs",
"target": "es6",
"noImplicitAny": false,
"sourceMap": false,
"typeRoots": ["node_modules/@types"]
},
"exclude": [
"node_modules"
]
} webpack.config.js module.exports = {
entry: {
app: ['babel-polyfill', './src/'],
test: ['babel-polyfill', './spec/'],
},
output: {
path: __dirname,
filename: './dist/[name].js',
},
resolve: {
extensions: ['', '.js', '.ts'],
},
module: {
loaders: [{
test: /\.ts$/, loaders: ['babel-loader', 'ts-loader'], exclude: /node_modules/
}],
}
}; Dependencies: "devDependencies": {
"@types/mocha": "^2.2.28",
"@types/node": "^4.0.30",
"babel-core": "^6.10.4",
"babel-loader": "^6.2.4",
"babel-polyfill": "^6.9.1",
"babel-preset-es2015": "^6.9.0",
"babel-preset-stage-0": "^6.5.0",
"mocha": "^2.5.3",
"rimraf": "^2.5.3",
"ts-loader": "^0.8.2",
"typescript": "^2.0.0",
"webpack": "^1.13.1"
} On VSCode and webpack it fails, but if I try to build the test file directly:
or It works. If I do a |
what do you mean it fails? what version of VS code? and do you have |
this is working for me with latest TS in VSCode. the webpack seems like a ts-loader issue. |
i.e. using the latest TS in VS Code, see https://github.com/Microsoft/TypeScript-Handbook/blob/master/pages/Nightly%20Builds.md#visual-studio-code |
Setting that |
Just the hack I needed too! |
just as a clarification. the |
i am getting error unknown compiler option types. but while checking tsc -v i am getting Version 2.0.0 |
what is the compiler option? |
{
"compilerOptions": {
"target": "es5",
"module": "amd",
"declaration": true,
"removeComments": true,
"noLib": false,
"experimentalDecorators": true,
"sourceMap": true,
"pretty": true,
"allowUnreachableCode": false,
"allowUnusedLabels": false,
"noImplicitAny": true,
"noImplicitReturns": true,
"noImplicitUseStrict": false,
"noFallthroughCasesInSwitch": true,
"allowJs": false,
"forceConsistentCasingInFileNames": true,
"moduleResolution": "node",
"types": ["jasmine","jasmine-ajax","requirejs","chai","es6-promise"]
},
} |
looks good to me. also working correctly for me on |
using gulp command "gulp build". is am need to update gulp typescript? |
probably :) these are new features in TS 2.0 |
I'm facing problems too (related to
package.json
|
I'm having random problems with TS 2.1.5 on VS 2015. Some of the dependencies inside @types are seen by Visual Studio, some aren't. This happens sometimes only, and I cannot pinpoint any specific reason. Yesterday things were working fine, put my laptop to sleep, today VS cannot see some types. Restarted VS and nothing. Compilation using gulp works fine every time, but VS is very unstable. Is there any way to debug which declarations VS is looking at? |
So the same project, no changes, sometimes work others not? if so can you share the project? can you also say when it does not work? or at least what activity you have noticed to trigger this behavior more often than others. |
@mhegazy Found out what was causing the issue. A node_modules folder was created deep in the project tree and that was messing with tsc. Added to the fact that VS doesn't show this folder in the list, I didn't see this before. This probably happened other times, but as I occasionally run a |
I don't see why this is closed I am using 2.1.5 and have tried everything listed above but cannot seem to use @types/chalk , @types/commander, and @types/nedb doesnt seem to function? @mhegazy |
Please file a new issue and provide enough details to allow us to diagnose the issue. |
I'm having trouble with sub-dependencies of libraries that are properly referenced node_modules@types. The result is (for me) a long list of build errors like this: Build:Cannot find type definition file for 'pinkie-promise'. I'm guessing 'pinkie-promise' is a library required by one of the @types libraries. If it's a sub-dependency of one of the 'normal' dependencies, I'll have other questions. here's the devDependencies and dependencies area of my package.json:
|
My solution for this was to add
This meant that the (I was having problems with the jquery @types not finding typescript's types). |
use |
also #15732 tracks adding lib reference directives. |
@mhegazy I was already using it, but it didn't help:
Without explicitly including
|
@mhegazy Here's the project: https://github.com/viewdir/manifold (latest code on master) |
That's because you are now explicitly setting "lib": ["es6", "dom"] |
@aluanhaddad Awesome, that solved it. Many thanks! |
Sorry to necro, but I've spent a day on this and finally resolved it. It seems to be a different resolution from others here (as it's a different cause, but it is a problem related to using @types), so figured it'd be useful to add. I am using Visual Studio 2015 and currently in the process of upgrading an old Asp.NET MVC site. Basic plan was to upgrade Typescript to latest (2.8.3) and remove all of the manual I started re-adding types using: Issue 1: Now we have some intellisense. JQuery is recognized, however it was still producing an error (module in an inaccessible location). After a lot of investigation I realised the JS files were being compiled correctly by the Typescript compiler, even with the errors, which ended up leading me to the next fix. Issue 2: I hope that helps someone out. Sorry if this is the wrong place to post this! |
@brunolm - Your solution works for me... Thanks a lot... In tsconfig.json : Corrected typeRoot values like following -> "typeRoots": ["node_modules/@types"] { |
Hi @nvivo, what do you mean by " A node_modules folder was created deep in the project tree"? And how come it's a random issue if there is always a node+modules folder? Thanks! |
What if we want to use types definitions in a library and skip having to explicitly build the library before serving the workspace ? It gives me the issue of the types definitions being missing again. |
This issue is normally resolved on my laptop by me reinstalling the node modules and then also restarting VSCode since it is incredibly buggy regarding Typescript (ironic since Microsoft develop both and still can't fix the bugs that have been around for years). |
Make sure you have inside the
|
To solve this
|
idk |
I had to comment out the
|
My issue was painfully simple after spending a good amount of time on it: My @types version did not match the version of the dependency I needed the types for. |
TypeScript Version: 2.0.0-beta
We are encountering various problems using types installed into node_modules/@types. My understanding was that, when types were installed there, the compiler would automatically pick them up, but that does not seem to happen.
If I install @types/angular, then try to use angular-cookies:
I get the following:
This is despite angular-cookies.d.ts defining an angular.cookies namespace.
If I install @types/rx, then try to import rx-lite:
It cannot find the module:
The only way I've found to fix this is to add an explicit entry to tsconfig.json types:
I thought the compiler included everything in node_modules/@types automatically, so why do I have to add this explicitly?
Similar to the above, if I install @types/tinycolor, which declares a module "tinycolor2" in its index.d.ts, then try to use it:
It cannot find the module:
Again, the only way to make it pick up this is to add an explicit entry to tsconfig.json's types section.
I'm not sure what the benefit of @types is, if we always have to add explicit config entries for our ambient type definitions in order for the compiler to consider them?
The text was updated successfully, but these errors were encountered: