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

Typings nightmare with @types/xxx #11437

Closed
tomitrescak opened this issue Oct 7, 2016 · 11 comments
Closed

Typings nightmare with @types/xxx #11437

tomitrescak opened this issue Oct 7, 2016 · 11 comments
Labels
Question An issue which isn't directly actionable in code

Comments

@tomitrescak
Copy link

tomitrescak commented Oct 7, 2016

This is not a bug, rather call for help.
Since recently packages started to install dependencies from @types repo.

From this moment on none of my projects is compilable as I am using Mocha for my tests, yet one of the packages uses Jest. Both of these packages declare "describe. it ..." in the global space.

So, I have @types/jest and @types/mocha installed in the node_modules folder.

As a result, no project will compile and my CI is out of order.

The only possibility that comes to my mind is to roll back to "classic" module resolution and copy the definitions into my project manually.

Is this true? Is there anything else I can do?

[EDIT]

I put moduleResolution to "classic" and it is still compiling stuff in the @types folder!!! WHY?

@yortus
Copy link
Contributor

yortus commented Oct 7, 2016

I am using Mocha for my tests, yet one of the packages uses Jest

Shouldn't that package have @types/jest as a devDependency rather than as a dependency? Then @types/jest won't be installed when you npm install your own module.

Generally the packages you depend on should not bring in their development dependencies (built/test infrastucture), just their executable code. But I can't really tell if this is the situation from the description above.

@tomitrescak
Copy link
Author

Well, I am not that package developer and this is what happens. Installing that package "Jest" appears in my typings folder.

@yortus
Copy link
Contributor

yortus commented Oct 7, 2016

Can I ask what the package is? If it is a deps vs devDeps issue in their package, then the fix is simple for them to make and the problem will go away for you.

@tomitrescak
Copy link
Author

Hi, I already created an issue with this. But I guess, the problem is not so isolated. Is there any other mean of protection from this apart from waiting for package developer to update and release a new version? Thanks.

@yortus
Copy link
Contributor

yortus commented Oct 7, 2016

Hopefully someone else can answer if there's a workaround for this.

In the mean time it would be helpful if the team promoted the proper use of devDependencies with @types typings. In recent blog posts (e.g. here and here) they show installing @types as normal dependencies, which means all clients of such packages will also needlessly get those types installed, even though they are not needed to run the package code.

At best it's a useless dependency for clients, but sometimes it may lead to clashes/errors such as the one you've reported here.

@weswigham
Copy link
Member

weswigham commented Oct 7, 2016

If you want a complex workaround, you should be able to manually remove the unwanted folder from your transitive @types by running npm shrinkwrap to pickle your dependencies, then edit the generated npm-shrinkwrap.json to remove the @types package you do not want to include. Then just delete it from disk and the shrinkwrap should prevent it from being installed for anyone else.

It's a bit of a kludge, but it can workaround packaging dependency conflicts like this.

@tomitrescak
Copy link
Author

I was really hoping that skipDefaultLibCheck will do good here as it its said to skip validation of .d.ts files, but it seems to do nothing as .d.ts files are still validated :/

@mhegazy
Copy link
Contributor

mhegazy commented Oct 7, 2016

@tomitrescak, just to make sure i understand, there are two projects, one depend on mocha, while the other use Jest? or is it that you have projects that depend on both?

if it is the earlier, then the fix is to use "types" : ["mocha"] in your tsconfig.json; this will instruct the compiler to only load @types/mocha in this project, then for the other project "types" : ["jest"] .

if it is the later. then what you need is to "break the tie" between the two declarations in some way. so options, consider creating a new folder: "overrides" , and add "overrides\jest\index.d.ts" to be what you thinkjestshould be. then update your tsconfig.json to include"typeRoots": [".\overrides", ".\node_modules@types"]. What this does it tells the compiler to look for types first in".\overrides\jest"and if it did not find it to look in".\node_modules@types\jest"`.

Ultimately the fix is on the declaration file side, and i would recommend you send a PR to DT with a fix that removes the declaration of it, declare etc.. to a different package that both jest and mocha depend on.

See http://www.typescriptlang.org/docs/handbook/tsconfig-json.html#types-typeroots-and-types for more details on this.

@tomitrescak
Copy link
Author

tomitrescak commented Oct 9, 2016

@mhegazy thanks for the explanation. That link really helped. My problem was the first one, where a project I'm depending on was installing "jest" into @types folder, while I am using mocha. They both depend on global variables which were clashing.

Would be great to point to that page in the list of the compiler options.

mhegazy added a commit to microsoft/TypeScript-Handbook that referenced this issue Oct 10, 2016
@mhegazy
Copy link
Contributor

mhegazy commented Oct 10, 2016

Added links to docs in microsoft/TypeScript-Handbook@a83f002

@mhegazy mhegazy added the Question An issue which isn't directly actionable in code label Oct 10, 2016
@tomitrescak
Copy link
Author

Fantastic, thanks!

alexinea added a commit to dotnetcore-internal/TypeScript-Handbook that referenced this issue Dec 29, 2016
* Add release notes

* Remove headers

* Add links to documentation for @types, --types and --typeRoots

Referenced in microsoft/TypeScript#11437 (comment)

* Update Compiler Options.md

Fix minor typo.

* Mention Babel at top of Gulp tutorial.

* IntelliJ Mac for nightly builds

Maybe include IntelliJ IDEA IDE for mac, too?

* Updated whitespaces and empty lines

* Use 'awesome-typescript-loader', use SFCs.

* Mentioned support for --outFile together with AMD or System

* Fixed broken link in React Webpack tutorial

 Updated the path reference to the page about tsconfig.json as it was broken.

* Fixes microsoft#420

clarifies Do's and Don'ts Use Optional Parameters section

See https://gist.github.com/agrberg/7bf64c61d3c6de0c638e7c0bc4742000 for
more details

* Change </br> to <br/>

* Fix microsoft/TypeScript#10433

* Fix microsoft/vscode#14322

* Fix paths example: target should be "jquery", not "jquery.d.ts"

Also add missing closing braces and have all json consistently use 2 space indents.

* Port fix in microsoft#432

* Fix lint failure

* Fixed typo

* Invoke origin setter in Decorators.md

* Add object rest/spread

* Update compiler options for TS 2.1

* Review comments

* Fix microsoft#348

* Review comments

* Add TypeScript 2.1 release notes

* Reorder

* Fix typo

* Minor typo

* Document index and indexed access types

* Document mapped types

* Reword and reorder index types discussion

* Fix module import

* Grammar fix

* Review comments

* Simplify keyof

* Fix typos

* Reorder mapped types example

Based on the more involved discussion from the blog post.

* Minor edits from PR comments

* Discuss mapped type inference and call out terms better

* Move index and map types to end of Advanced Types

The feature depends on type aliases and string literal types, so
should come after those.

* Document [non-]nullable types

* Does not require `this.` before props in the stateless functional component example

* `Hello` must be exported to be used in `index.tsx`

* Removed typo square bracket

* Minor formatting tweak from PR comments

* Mention there are currently 2 webpack loaders for typescript and link to more information

Fixes microsoft#450

* Fix defaults for `--importHelpers`

* Add breaking change link to release-notes

* Fix typo in variable reference

* Fix two small errors in React + Webpack tutorial.

* fixing #12872, add a mistype to show the usage of optional properties

* Fix typos

* Change the phrasing on webpack typescript loaders to be more clear

* Update Interfaces.md

* Update Interfaces.md

* limit files to just the src directory

* Update 'include' in React guide.
@microsoft microsoft locked and limited conversation to collaborators Jun 19, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Question An issue which isn't directly actionable in code
Projects
None yet
Development

No branches or pull requests

4 participants