Skip to content

Fix broken type definitions for extend-expect.d.ts #101

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

Merged
merged 1 commit into from
May 7, 2019
Merged

Fix broken type definitions for extend-expect.d.ts #101

merged 1 commit into from
May 7, 2019

Conversation

mdgozza
Copy link
Contributor

@mdgozza mdgozza commented May 6, 2019

What/Why: #93 introduced a regression into the TypeScript definitions. It used invalid TypeScript syntax and re-declared properties like not which conflict with @types/jest. Errors for an empty TypeScript project:

./node_modules/jest-dom/extend-expect.d.ts:11:5 - error TS2717: Subsequent property declarations must have the same type.  Property 'not' must be of type 'InverseAsymmetricMatchers', but here has type 'InverseStringAsymmetricMatchers'.

11     not: InverseStringAsymmetricMatchers
       ~~~

./node_modules/jest-dom/extend-expect.d.ts:16:7 - error TS2713: Cannot access 'Expect.stringContaining' because 'Expect' is a type, but not a namespace. Did you mean to retrieve the type of the property 'stringContaining' in 'Expect' with 'Expect["stringContaining"]'?

16     | Expect.stringContaining
         ~~~~~~~~~~~~~~~~~~~~~~~

./node_modules/jest-dom/extend-expect.d.ts:17:7 - error TS2713: Cannot access 'Expect.stringMatching' because 'Expect' is a type, but not a namespace. Did you mean to retrieve the type of the property 'stringMatching' in 'Expect' with 'Expect["stringMatching"]'?

17     | Expect.stringMatching
         ~~~~~~~~~~~~~~~~~~~~~

./node_modules/jest-dom/extend-expect.d.ts:18:7 - error TS2713: Cannot access 'Expect.any' because 'Expect' is a type, but not a namespace. Did you mean to retrieve the type of the property 'any' in 'Expect' with 'Expect["any"]'?

18     | Expect.any
         ~~~~~~~~~~

./node_modules/jest-dom/extend-expect.d.ts:19:7 - error TS2713: Cannot access 'Expect.anything' because 'Expect' is a type, but not a namespace. Did you mean to retrieve the type of the property 'anything' in 'Expect' with 'Expect["anything"]'?

19     | Expect.anything
         ~~~~~~~~~~~~~~~

./node_modules/jest-dom/extend-expect.d.ts:20:7 - error TS2713: Cannot access 'Expect.not' because 'Expect' is a type, but not a namespace. Did you mean to retrieve the type of the property 'not' in 'Expect' with 'Expect["not"]'?

20     | Expect.not
         ~~~~~~~~~~

How: This PR fixes the types based on the intentions of the author of #93 and the types in @types/jest. Unfortunately, Jest does not provide better typings for matchers like expect.stringContaining('foo') than any.

https://github.com/DefinitelyTyped/DefinitelyTyped/blob/d17c14a550e68b0a1811afabd40677c7580f3579/types/jest/index.d.ts#L482

Checklist:

  • Documentation (n/a)
  • Tests (n/a)
  • Updated Type Definitions
  • Ready to be merged
  • Added myself to contributors table

#93 introduced a regression into the TypeScript definitions. It used invalid TypeScript syntax and re-declared properties like `not` which conflict with `@types/jest`. Errors for an empty TypeScript project:

```
./node_modules/jest-dom/extend-expect.d.ts:11:5 - error TS2717: Subsequent property declarations must have the same type.  Property 'not' must be of type 'InverseAsymmetricMatchers', but here has type 'InverseStringAsymmetricMatchers'.

11     not: InverseStringAsymmetricMatchers
       ~~~

./node_modules/jest-dom/extend-expect.d.ts:16:7 - error TS2713: Cannot access 'Expect.stringContaining' because 'Expect' is a type, but not a namespace. Did you mean to retrieve the type of the property 'stringContaining' in 'Expect' with 'Expect["stringContaining"]'?

16     | Expect.stringContaining
         ~~~~~~~~~~~~~~~~~~~~~~~

./node_modules/jest-dom/extend-expect.d.ts:17:7 - error TS2713: Cannot access 'Expect.stringMatching' because 'Expect' is a type, but not a namespace. Did you mean to retrieve the type of the property 'stringMatching' in 'Expect' with 'Expect["stringMatching"]'?

17     | Expect.stringMatching
         ~~~~~~~~~~~~~~~~~~~~~

./node_modules/jest-dom/extend-expect.d.ts:18:7 - error TS2713: Cannot access 'Expect.any' because 'Expect' is a type, but not a namespace. Did you mean to retrieve the type of the property 'any' in 'Expect' with 'Expect["any"]'?

18     | Expect.any
         ~~~~~~~~~~

./node_modules/jest-dom/extend-expect.d.ts:19:7 - error TS2713: Cannot access 'Expect.anything' because 'Expect' is a type, but not a namespace. Did you mean to retrieve the type of the property 'anything' in 'Expect' with 'Expect["anything"]'?

19     | Expect.anything
         ~~~~~~~~~~~~~~~

./node_modules/jest-dom/extend-expect.d.ts:20:7 - error TS2713: Cannot access 'Expect.not' because 'Expect' is a type, but not a namespace. Did you mean to retrieve the type of the property 'not' in 'Expect' with 'Expect["not"]'?

20     | Expect.not
         ~~~~~~~~~~
```

This PR fixes the types based on the intentions of the author of #93 and the types in `@types/jest`. Unfortunately, Jest does not provide better typings for matchers like `expect.stringContaining('foo')` than `any`.

https://github.com/DefinitelyTyped/DefinitelyTyped/blob/d17c14a550e68b0a1811afabd40677c7580f3579/types/jest/index.d.ts#L482
@gnapse gnapse merged commit 44f0020 into testing-library:master May 7, 2019
@gnapse
Copy link
Member

gnapse commented May 7, 2019

🎉 This PR is included in version 3.2.1 🎉

The release is available on:

Your semantic-release bot 📦🚀

@gnapse gnapse added the released label May 7, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants