-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Update TypeScript to 4.8.4 #6346
Update TypeScript to 4.8.4 #6346
Conversation
Install tslib in the monorepo's root package.json since it's required by the es5 downleveling we do in rollup bundles.
cc @pyu10055 |
According to the ESModules standard, code can not modify properties of modules. TypeScript 4 will enforce this rule. This in particular affects tests for executors in tfjs-converter, in which we often spy on tfOps. This PR removes all instances of `spyOn(tfOps,...)` and replaces them with a separate `spyOps` mock / fake which is passed to the `executeOp` function. This PR was part of the larger TS4 upgrade PR (tensorflow#6346), but I'm splitting that PR into pieces that can be merged while we're still using TS3 because it's too large to keep up-to-date.
According to the ESModules standard, code can not modify properties of modules. TypeScript 4 will enforce this rule. This in particular affects tests for executors in tfjs-converter, in which we often spy on tfOps. This PR removes all instances of `spyOn(tfOps,...)` and replaces them with a separate `spyOps` mock / fake which is passed to the `executeOp` function. This PR was part of the larger TS4 upgrade PR (tensorflow#6346), but I'm splitting that PR into pieces that can be merged while we're still using TS3 because it's too large to keep up-to-date.
According to the ESModule standard, properties of modules are immutable. TypeScript 4 will enforce this rule. This in particular affects tests for executors in tfjs-converter, in which we often spy on tfOps. This PR removes all instances of spyOn(tfOps,...) and replaces them with a separate spyOps mock / fake which is passed to the executeOp function. It also removes spying on the io module in graph_model_test.ts. This PR was part of the larger TS4 upgrade PR (#6346, #5561), but I'm splitting that PR into pieces that can be merged while we're still using TS3 because it's too large to keep up-to-date. This PR also bumps lib to es2019 in the root tsconfig to allow using Object.fromEntries. This shouldn't affect the code we ship since it's still compiled to the es2017 target. Note that this PR does not bump TypeScript to version 4. It leaves it at 3.
0b69786
to
dc6de9c
Compare
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.
Thank you Matt for this huge task!
Reviewed 11 of 89 files at r1, 1 of 8 files at r2, 69 of 85 files at r3, 10 of 16 files at r4, 9 of 10 files at r5, 7 of 7 files at r6, all commit messages.
Reviewable status:complete! 1 of 1 approvals obtained (waiting on @Linchenn and @mattsoulanille)
tfjs-core/scripts/test_snippets/util.ts
line 168 at r6 (raw file):
for (let i = 0; i < tags.length; i++) { const jsdocTag = tags[i]; if (jsdocTag.name === 'doc' && jsdocTag.text) {
google TS style guide still recommend use != null and == null for null check
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.
Great job! Thank you Matt!
This major release upgrades TypeScript from 3.5.3 to 4.8.4 (#6346). It is intended to be as non-breaking as possible, but it technically has breaking changes for users of `typescript<4.4`. All other users should be unaffected. When compiling projects that depend on TFJS with `typescript<4.4`, the following error will appear. ``` node_modules/@webgpu/types/dist/index.d.ts:587:16 - error TS2304: Cannot find name 'PredefinedColorSpace'. 587 colorSpace?: PredefinedColorSpace; ~~~~~~~~~~~~~~~~~~~~ ... ``` This can be fixed by upgrading TypeScript to 4.4.2 or greater, or by adding the file `predefined_color_space.d.ts` (name and path can be changed) with the following contents to your project to define the missing type. If this file is added, it will need to be removed when TypeScript is upgraded past 4.3. ```typescript type PredefinedColorSpace = "display-p3" | "srgb"; ``` `typescript<3.7` has the following additional error. ``` node_modules/@tensorflow/tfjs-core/dist/engine.d.ts:127:9 - error TS1086: An accessor cannot be declared in an ambient context. 127 get backend(): KernelBackend; ~~~~~~~ ... ``` Enabling [`skipLibCheck`](https://www.typescriptlang.org/tsconfig#skipLibCheck) suppresses this error, and upgrading to at least TypeScript 3.6.2 fixes it (although the above fix for `PredefinedColorSpace` will also need to be applied).
This PR updates TypeScript from 3.5.3 to 4.8.4.
Tests need to be rewritten to avoid spying on properties of imported objectsThis is done.There's a test failure with TypeScript 4.4.2: This is now fixedNeeds to be tested.react-native may need other fixes before TS4 and should be updated in a different PR.These changes will let us add the
useUnknownInCatchVariables
andnoImplicitOverride
flags to the tsconfig (in a separate PR).Closes #5561, which has gone through review, but was not merged because of breaking changes introduced by typescript 4.4.2.
To see the logs from the Cloud Build CI, please join either our discussion or announcement mailing list.
This change is