-
Notifications
You must be signed in to change notification settings - Fork 403
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
Add types to package.json #135
Conversation
package.json
Outdated
@@ -3,6 +3,7 @@ | |||
"version": "0.0.0-semantically-released", | |||
"description": "Custom jest matchers to test the state of the DOM", | |||
"main": "dist/index.js", | |||
"types": "extend-expect.d.ts", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The problem with this is is that the main
file, dist/index.js
, does not extend the global expect
object. So only doing import @testing-library/jest-dom
will provide typings for the extensions but it will fail at runtime because expect
was not extended.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, sure. So we can instead use a folder. Let me test that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jgoz This has been updated, and is still working for me locally. You only get types if you import:
import '@testing-library/jest-dom/extend-expect';
@@ -3,6 +3,7 @@ | |||
"version": "0.0.0-semantically-released", | |||
"description": "Custom jest matchers to test the state of the DOM", | |||
"main": "dist/index.js", | |||
"types": ".", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think this actually does anything... import '@testing-library/jest-dom/extend-expect';
from a TS file has always worked.
Again, the point of #123 was to cheat (a bit) and make the extend-expect
typings available without needing any imports (i.e., make them "global" typings). But the only way to make them global typings is by moving them to DefinitelyTyped and defining them as global typings, rather than module typings.
This is something that the DT maintainers disagreed with, so barring some kind of TS compiler support for automatic global type resolution from types provided by npm packages, we are stuck.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For me, this did make a difference. Without this, it didn't work - I checked a few times.
However, I could get this to work otherwise.
import '@testing-library/jest-dom/extend-expect.d'
This may be environmental.
What's the status of this? And what's its relation with #123? Would it solve that issue? |
The changes in this PR won't have an effect on library users, so I don't see a reason to merge. TypeScript can find the |
Closing this based on the previous comment, and also under the light of our most recent effort to solve #123 (see #175, #182 and DefinitelyTyped/DefinitelyTyped#37792). |
What:
Resolves #123.
Why:
This property in
package.json
tells TypeScript where to find the types for thisjest-dom
.How:
A
lib
property was add topackage.json
.A user must only import the below into any
.ts
or.d.ts
file.Checklist: