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

chore: update to TypeScript 4.8 #13177

Merged
merged 4 commits into from
Aug 28, 2022
Merged

chore: update to TypeScript 4.8 #13177

merged 4 commits into from
Aug 28, 2022

Conversation

SimenB
Copy link
Member

@SimenB SimenB commented Aug 26, 2022

@SimenB
Copy link
Member Author

SimenB commented Aug 26, 2022

Aww.

@mrazauskas thoughts? we might need to patch ansi-escapes as it's ESM only in the latest versions

@mrazauskas
Copy link
Contributor

Sure. I will take a look bit later.

If ansi-escapes is the trouble, it is easy replaceable by adding a couple of tiny functions in jest-util. Some Ansi sequences already live there, e.g: https://github.com/facebook/jest/blob/630d099e2e7deeb38eac1aaccf37f7f9f9d77335/packages/jest-util/src/specialChars.ts#L18

Or with Node’s built-ins like WriteStream.prototype.cursorTo(), but somehow own functions sounds better.

@SimenB SimenB force-pushed the update-typescript branch from 0071941 to a97456f Compare August 26, 2022 13:38
@SimenB
Copy link
Member Author

SimenB commented Aug 28, 2022

It's not ansi-escapes actually, it's type-fest (I just read the error too quickly 😅): node_modules/ansi-escapes/node_modules/type-fest/ts41/get.d.ts

@@ -171,6 +171,7 @@
},
"resolutions": {
"@types/node": "~14.14.45",
"ansi-escapes/type-fest": "^2.0.0",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just did the same and it works ;D

There is also jasmine related error. I think it can be ignored with @ts-expect-error.

@SimenB SimenB merged commit 132e815 into jestjs:main Aug 28, 2022
@SimenB SimenB deleted the update-typescript branch August 28, 2022 15:09
@nfroidure
Copy link

nfroidure commented Aug 30, 2022

Since I updated to the last TypeScript version 4.8.2, I get the following type error :

node_modules/@jest/environment/build/index.d.ts:329:26 - error TS2430: Interface 'JestImportMeta' incorrectly extends interface 'ImportMeta'.
  The types returned by 'jest.createMockFromModule(...)' are incompatible between these types.
    Type 'unknown' is not assignable to type 'T'.
      'T' could be instantiated with an arbitrary type which could be unrelated to 'unknown'.

329 export declare interface JestImportMeta extends ImportMeta {
                             ~~~~~~~~~~~~~~


Found 1 error in node_modules/@jest/environment/build/index.d.ts:329

Do you think this commit will fix it on with the next version?

To test by yourself, just clone this module and npm i && npm run build :
https://github.com/nfroidure/common-services

@mrazauskas
Copy link
Contributor

@nfroidure I just followed the reproduction steps you provided. The library got build without any error.

The strange things: I see is that package-lock.json got modified; and I see "typescript": "^4.7.3" in your package.json. Not the version you are complaining about.

Changing the version to "^4.8.2" and running the commands again gives 117 TypeScript errors ("Found 117 errors in the same file, starting at: node_modules/knifecycle/dist/util.d.ts:100"). I can’t see nothing Jest related at the moment.

Might be something went wrong with reproduction. Just leaving a comment. Would be better to open a new issue with minimal reproduction.

@nfroidure
Copy link

The ^ make the latest version to be installed with npm (ie 4.8.2), you should see the Jest one in the several errors, the others are ones I fixed by my side. I'll try to reproduce it in a smaller repo.

@nfroidure
Copy link

Ok, I found the problem, it comes from @types/jest:

mkdir test && cd test
npm init -y
npm i -D typescript jest
npm i -d @types/jest
echo "import { jest } from '@jest/globals';" > test.ts
npm exec --package=typescript -- tsc test.ts

Gives:

node_modules/@jest/environment/build/index.d.ts:329:26 - error TS2430: Interface 'JestImportMeta' incorrectly extends interface 'ImportMeta'.
  The types returned by 'jest.createMockFromModule(...)' are incompatible between these types.
    Type 'unknown' is not assignable to type 'T'.
      'T' could be instantiated with an arbitrary type which could be unrelated to 'unknown'.

329 export declare interface JestImportMeta extends ImportMeta {
                             ~~~~~~~~~~~~~~


Found 1 error in node_modules/@jest/environment/build/index.d.ts:329

I'll report it to the concerned repo, thanks for your answer.

@mrazauskas
Copy link
Contributor

If you import { jest } from '@jest/globals', types of jest object will be pulled jest and the rest of global APIs will get typed through @types/jest.

I would recommend importing all APIs (describe, test, etc.) from @jest/globals. That way you will not need @types/jest and Jest’s types will be always up to date.

@github-actions
Copy link

This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
Please note this issue tracker is not a help forum. We recommend using StackOverflow or our discord channel for questions.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 30, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants