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

Upgrade TypeScript to v5.7 #1730

Open
wants to merge 1 commit into
base: eslint-tweak
Choose a base branch
from
Open

Upgrade TypeScript to v5.7 #1730

wants to merge 1 commit into from

Conversation

axelboc
Copy link
Contributor

@axelboc axelboc commented Jan 13, 2025

Supersedes #1715

TypeScript 5.5 can:

  • infer type predicates, notably when filtering arrays - e.g. myArr.filter(foo => !!foo).map(foo => foo.toString())
  • better narrow down obj[key] expressions
  • check the syntax of regular expressions
  • identify missing type annotations that may prevent future tools from type-checking in parallel with emitting declaration files (a bit early days to enable it, though)
    • I'm not sure if this happens because of TS 5.5 or 5.6, but I started getting errors like this: The inferred type <...> cannot be named without a reference to <some-node_modules-path>. Moving declaration: true out of the root tsconfig.json and into the tsconfig.build.json files of the packages made the error go away.
    • To avoid too much repetition in the tsconfig.build.json files, I created tsconfig.build.base.json (but I didn't move any of the options containing relative paths into it, like outDir, to avoid any issues).

TypeScript 5.6 can:

  • catch condition that are always true or always false by mistake
  • forbid side effect imports with a new option called noUncheckedSideEffectImports
    • With this option enabled, tsc reported the CSS imports in storybook/.storybook/main.ts as side effects imports.
    • I had to add an empty module declaration for *.css to src/types.d.ts, which I also decided to move to the root of the storybook folder.
  • emit declarations without type-checking (too early to use, though)
  • provide better code completions based on commit characters
  • be configured to no longer suggest some auto-imports
    • I'm taking advantage of this to stop VS Code from suggesting to auto-import log from Three.js or Node (because of @types/node) so that the console.log() snippet becomes the first suggestion.

TypeScript 5.7 can:

  • report more cases of never-initialised variables
    • There's such a case in scaleGamma.ts on a variable that is meant to represent the never type (i.e. undefined at runtime). I couldn't find a fix that played nicely with d3-scale's types, so I chose to turn off the error for now.
  • support ES2024 features
    • There's a change in the base types relating to ArrayBuffer, which I had to work around in h5wasm-api.test.ts. Also, typed arrays (Unit8Array, etc.) now have a generic that defaults to ArrayBufferLike (ArrayBuffer | SharedArrayBuffer), but this doesn't this to affect us.

Note that TypeScript and Node are also making progress towards being able to run TS files without pre-compilation out of the box.

@axelboc axelboc mentioned this pull request Jan 13, 2025
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.

1 participant