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

Update TypeScript to 4.8.4 #6346

Merged
merged 43 commits into from
Oct 11, 2022

Conversation

mattsoulanille
Copy link
Member

@mattsoulanille mattsoulanille commented Apr 23, 2022

This PR updates TypeScript from 3.5.3 to 4.8.4.

Chrome 92.0.4515.159 (Linux x86_64) perClassAccuracy renders histogram FAILED
	Error: Expected 0 to be 1.
	    at <Jasmine>
	    at src/show/tensor_test.ts:32:61 <- src/show/tensor_test.js:58:65
	    at Generator.next (<anonymous>)
	    at fulfilled (src/show/tensor_test.js:40:58)
  • tfjs (union package): Depends on converter
  • tfjs-node(-gpu), e2e: Depends on tfjs union.
  • tfjs-backend-webgpu: Done.
  • tfjs-react-native: Needs 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 and noImplicitOverride 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 Reviewable

@mattsoulanille
Copy link
Member Author

cc @pyu10055

mattsoulanille added a commit to mattsoulanille/tfjs that referenced this pull request Jun 23, 2022
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.
mattsoulanille added a commit to mattsoulanille/tfjs that referenced this pull request Jun 24, 2022
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.
mattsoulanille added a commit that referenced this pull request Jun 29, 2022
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.
@mattsoulanille mattsoulanille changed the title Update TypeScript to 4.4.2 Update TypeScript to 4.8.4 Sep 30, 2022
Copy link
Collaborator

@pyu10055 pyu10055 left a 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: :shipit: 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

Copy link
Collaborator

@Linchenn Linchenn left a 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!

@mattsoulanille mattsoulanille merged commit baa721b into tensorflow:4.x_dev Oct 11, 2022
mattsoulanille added a commit that referenced this pull request Oct 12, 2022
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).
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.

None yet

3 participants