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
Adding @testing-library/jest-dom type definitions #37688
Conversation
👋 Hi there! I’ve run some quick performance metrics against master and your PR. This is still an experiment, so don’t panic if I say something crazy! I’m still learning how to interpret these metrics. Let’s review the numbers, shall we? These typings are for a package that doesn’t yet exist on master, so I don’t have anything to compare against yet! In the future, I’ll be able to compare PRs to testing-library__jest-dom with its source on master. Comparison details 📊
If you have any questions or comments about me, you can ping |
@weyert Thank you for submitting this PR! Because this is a new definition, a DefinitelyTyped maintainer will be reviewing this PR in the next few days once the Travis CI build passes. In the meantime, if the build fails or a merge conflict occurs, I'll let you know. Have a nice day! |
Aren't these types already being exposed through the package with the d.ts? |
@PranavSenthilnathan if you can, checkout the discussion in testing-library/jest-dom#123. It gives you some context about what we're trying to achieve here. |
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.
This change is not needed. The package can add "types" field to the package and thats the desired way of adding types. Refer to https://github.com/Microsoft/TypeScript-Handbook/blob/master/pages/declaration%20files/Publishing.md
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.
This change is not needed. The package can add "types" field to the package and thats the desired way of adding types. Refer to https://github.com/Microsoft/TypeScript-Handbook/blob/master/pages/declaration%20files/Publishing.md
Yes, I understand but we decided to add as a dependency, like the other @testing-library packages. I kindly request to reconsider this decision as this would this library to not have type definitions. @sheetalkamat Please see this article https://blog.johnnyreilly.com/2019/08/symbiotic-definitely-typed.html for the reasoning for this approach. |
Hey @sheetalkamat
This PR adds types to Definitely Typed which will result in an As far as I can tell, this PR should be safe to merge assuming that my understanding of the desired direction is correct and so I've reopened it. Before we do merge let's be sure that we want this to be the direction for this package. The solution that @sheetalkamat suggested is eminently suitable as an alternative if @gnapse if happy to maintain. It's a choice; but let's be clear about which choice we want to make. I'm not sure that's entirely explicit as yet. Hopefully the responses to this comment: testing-library/jest-dom#123 (comment) will make it clear the direction that people want to go. |
Updated numbers for you here from 61602ba: These typings are for a package that doesn’t yet exist on master, so I don’t have anything to compare against yet! In the future, I’ll be able to compare PRs to testing-library__jest-dom with its source on master. Comparison details 📊
|
@weyert One or more reviewers has requested changes. Please address their comments. I'll be back once they sign off or you've pushed new commits or comments. Thank you! |
// Ernesto García <https://github.com/gnapse> | ||
// Weyert de Boer <https://github.com/weyert> | ||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped | ||
// TypeScript Version: 3.0 |
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.
According to https://github.com/testing-library/jest-dom#usage this you need to have extend-expect
to be present that contains the globals
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.
Yes, as this library is extending expect() to have more matchers.
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.
What I meant was there needs to be a file extend-expect.d.ts
that defines all the global declaraitons.
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped | ||
// TypeScript Version: 3.0 | ||
|
||
declare namespace jest { |
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.
This is not going to work with import {toBeInTheDocument, toHaveClass} from '@testing-library/jest-dom'
as per https://github.com/testing-library/jest-dom#usage
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 am not sure how to support this alternative way of using the library with TypeScript. Do we want to support the not typical usage of the library? Any tips how this could be resolved?
By exposing both ways extending the jest namespace and export as a typical type outside the namespace to allow covering this?
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.
Please read https://github.com/DefinitelyTyped/DefinitelyTyped#how-do-i-write-definitions-for-packages-that-can-be-used-globally-and-as-a-module for details on how to write definitions that are available as module or global
Hello @sheetalkamat, @johnnyreilly. Looks like there is a little change of plan regarding this type definition. The idea now is to keep the type definition in the actual package Would this be acceptable? |
See response of @sheetalkamat for the above question here: |
Closing pull request as it's not needed |
Please fill in this template.
npm test
.)npm run lint package-name
(ortsc
if notslint.json
is present).Select one of these and delete the others:
If adding a new definition:
.d.ts
files generated via--declaration
dts-gen --dt
, not by basing it on an existing project.tslint.json
should be present, andtsconfig.json
should havenoImplicitAny
,noImplicitThis
,strictNullChecks
, andstrictFunctionTypes
set totrue
.If changing an existing definition:
tslint.json
containing{ "extends": "dtslint/dt.json" }
.If removing a declaration:
notNeededPackages.json
.