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

Add types to package.json #135

Closed
wants to merge 2 commits into from
Closed

Add types to package.json #135

wants to merge 2 commits into from

Conversation

mrmckeb
Copy link

@mrmckeb mrmckeb commented Oct 2, 2019

What:

Resolves #123.

Why:

This property in package.json tells TypeScript where to find the types for this jest-dom.

How:

A lib property was add to package.json.

A user must only import the below into any .ts or .d.ts file.

import '@testing-library/jest-dom/extend-expect';

Checklist:

  • Documentation
  • Tests N/A
  • Updated Type Definitions N/A
  • Ready to be merged

@mrmckeb mrmckeb changed the title Update package.json Add types to package.json Oct 2, 2019
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",
Copy link
Collaborator

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.

Copy link
Author

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.

Copy link
Author

@mrmckeb mrmckeb Oct 2, 2019

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';

@mrmckeb mrmckeb requested a review from jgoz October 2, 2019 15:10
@@ -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": ".",
Copy link
Collaborator

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.

Copy link
Author

@mrmckeb mrmckeb Oct 2, 2019

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.

@gnapse
Copy link
Member

gnapse commented Nov 20, 2019

What's the status of this? And what's its relation with #123? Would it solve that issue?

@jgoz
Copy link
Collaborator

jgoz commented Nov 20, 2019

This PR does not solve #123, unfortunately. There is no way to solve #123 entirely within our project. The only way to do that involves the @types/ hack that the DefinitelyTyped team did not accept (as far as I'm aware).

@gnapse
Copy link
Member

gnapse commented Nov 21, 2019

Ok, we'll continue the discussion about #123 over there.

Is there any value in merging this regardless of it solving #123?

@jgoz
Copy link
Collaborator

jgoz commented Nov 21, 2019

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 index.d.ts types without a "types" property in package.json and people will still need to manually include extend-expect.d.ts somewhere.

@gnapse
Copy link
Member

gnapse commented Jan 20, 2020

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).

@gnapse gnapse closed this Jan 20, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Make it so the TypeScript definitions work automatically without config
3 participants