-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
@types from developer dependencies interfere with own project #9731
Comments
In your tsconfig.json, add this (at the same level as "compilerOptions" or "files"): "types": [], This will effectively disable the automatic enumeration of |
/cc @DanielRosenwasser -- this is a concrete reason to encourage package authors to not put |
There needs to be a mechanism though for expressing "I am also going to need this other API". npm handles this through peerDependencies and of npm@3 those will not get installed automatically but simply warn that they need to be present. It seems logical that |
FWIW someone on our team was talking to the NPM people and it sounds like they may be open to some new form of dependency (if we implement it for them, presumably 😉). I feel like a recursive-walking dev-dependency is what we want, but we need to figure out what the scenarios are and spec it all out before going down that road. |
Awesome. These sort of ambient dependencies, where there can be two levels of "versioning" (the version the ambient definition is describing and the version of the ambient definition). It would also be nice to potentially resolve the ambient dependency automagically based on the run-time dependency. Would be glad to add to the conversation if it gets serious with npm. |
Thanks for the suggestion but for some reason this is not working properly for me. If I just run |
So what is the best approach right now to handle @types/ scope dependencies when I want to avoid installing all @types/ manually? My idea would be to define them as peer dependencies and build a separate tool that
|
@poke your tsconfig.json should be: {
"compilerOptions": {
"types" : []
}
} |
@mhegazy Oh, so |
i do not think it has ever been other than that. only include, exclude, files are siblings to compilerOptions. |
…t globs now I no longer need the gulpfile nor the gulp-related dependencies as all I've needed them for can now be done with tsc alone. The only trouble is that @types/jasmine package coming from protractor interferes with @types/mocha that I'm using to test Serenity/JS. Hopefully the amazing TypeScript guys will come up with some nice solution to that problem ;-) See microsoft/TypeScript#9731 for details. For now I'll list the @types manually in tsconfig; a bit ugly, but better than the compiler throwing errors.
@RyanCavanaugh - The guidance given here to fix the conflicting types in
This means that even if the declaration is not being included automatically as an ambient declaration, another dependency can explicitly import that dependency and you can still end up with conflicting global declarations. Am currently experiencing this with a project that is including (and importing) i.e: .../node_modules/@types/storybook__react/node_modules/@types/react/index.d.ts
(3544,13): error TS2403: Subsequent variable declarations must have the same type.
Variable 'a' must be of type 'DetailedHTMLProps<AnchorHTMLAttributes<HTMLAnchorElement>, HTMLAnchorElement>',
but here has type 'DetailedHTMLProps<AnchorHTMLAttributes<HTMLAnchorElement>, HTMLAnchorElement>'. |
In case it helps anyone else, I managed to fix my issue of clashing |
(TypeScript 2.0.0 beta)
Developer dependencies imported using the npm
@types
namespace interfere with my project specific types.In my case, I have a web project that should use TypeScript’s default type definitions. My developer dependencies however include something that requires beautylog which itself depends on the package typings-global that has a dependency on @types/node.
This causes some standard definitions to be overwritten with Node-specific definitions. For example,
setTimeout()
will return aNodeJS.Timer
object (instead of a number).So when using
setTimeout()
in my web application and attempt to save the return value into a number variable, I get an error since I cannot assign aNodeJS.Timer
to that type. But using thatNodeJS.Timer
type would be wrong since that’s not what happens in the browser.So a dependency of a dependency of a dependency … has some type definitions which is added into
node_modules/@types/
which then causes my project to also load those although they are not relevant (and actually conflicting) to my project.Is there any solution to this? npm 3’s “let’s try to put everything flat into
node_modules
” essentially creates a whole new scoping problem with TypeScript 2’s type definition resolution.(I’ve also created an issue about this on beautylog’s repository.)
The text was updated successfully, but these errors were encountered: