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

UI dev dependencies typescript 4.9.3 #3856

Merged
merged 2 commits into from Nov 21, 2022

Conversation

pedrottimark
Copy link
Contributor

@pedrottimark pedrottimark commented Nov 20, 2022

Description

TypeScript releases a minor update every quarter.

https://github.com/microsoft/TypeScript/releases/tag/v4.9.3

  1. https://devblogs.microsoft.com/typescript/announcing-typescript-4-9/#the-satisfies-operator

    TypeScript developers are often faced with a dilemma: we want to ensure that some expression matches some type, but also want to keep the most specific type of that expression for inference purposes.

    The new satisfies operator lets us validate that the type of an expression matches some type, without changing the resulting type of that expression.

    satisfies can be used to catch lots of possible errors.

  2. https://devblogs.microsoft.com/typescript/announcing-typescript-4-9/#unlisted-property-narrowing-with-the-in-operator

    As developers, we often need to deal with values that aren’t fully known at runtime. In fact, we often don’t know if properties exist, whether we’re getting a response from a server or reading a configuration file. JavaScript’s in operator can check whether a property exists on an object.

    TypeScript 4.9 makes the in operator a little bit more powerful when narrowing types that don’t list the property at all. Instead of leaving them as-is, the language will intersect their types with Record<"property-key-being-checked", unknown>.

  3. https://devblogs.microsoft.com/typescript/announcing-typescript-4-9/#checks-for-equality-on-nan

    TypeScript now errors on direct comparisons against NaN, and will suggest using some variation of Number.isNaN instead.

  4. https://devblogs.microsoft.com/typescript/announcing-typescript-4-9/#file-watching-now-uses-file-system-events

    In earlier versions, TypeScript leaned heavily on polling for watching individual files. Using a polling strategy meant checking the state of a file periodically for updates.

    In TypeScript 4.9, file watching is powered by file system events by default, only falling back to polling if we fail to set up event-based watchers. For most developers, this should provide a much less resource-intensive experience when running in --watch mode, or running with a TypeScript-powered editor like Visual Studio or VS Code.

  5. https://devblogs.microsoft.com/typescript/announcing-typescript-4-9/#remove-unused-imports-and-sort-imports-commands-for-editors

    In TypeScript 4.3, we introduced a command called "Sort Imports" which would only sort imports in the file, but not remove them.

    TypeScript 4.9 adds the other half, and now provides "Remove Unused Imports". TypeScript will now remove unused import names and statements, but will otherwise leave the relative ordering alone.

    Visual Studio Code (1.73 and later) will have support built in and will surface these commands via its Command Palette.

  6. https://devblogs.microsoft.com/typescript/announcing-typescript-4-9/#go-to-definition-on-return-keywords

    In the editor, when running a go-to-definition on the return keyword, TypeScript will now jump you to the top of the corresponding function. This can be helpful to get a quick sense of which function a return belongs to.

    We expect TypeScript will expand this functionality to more keywords such as await and yield or switch, case, and default.

  7. What’s Next

    Our next release will be TypeScript 5.0 – but have no fear, we believe 5.0 should be pretty easy to adopt.

    TypeScript 5.0 Iteration Plan microsoft/TypeScript#51362

Errors

Because yarn build reports only the first error, and not even the name of the file:

  1. yarn tsc in ui/apps/platform

    • src/Containers/Clusters/ClustersSidePanel.tsx

      error TS2345: Argument of type '"DEPLOYMENT"' is not assignable to parameter of type 'SetStateAction<"FORM">'.

      setWizardStep(wizardSteps.DEPLOYMENT);

      error TS2367: This comparison appears to be unintentional because the types '"FORM"' and '"DEPLOYMENT"' have no overlap.

      {!isBlocked && wizardStep === wizardSteps.DEPLOYMENT && (
  2. yarn tsc in ui/packages/ui-components

Solution

  1. Replace object in helpers file with string union type in component file.
  2. Declare type of useState hook.

Checklist

  • Investigated and inspected CI test results
  • Unit test and regression tests added

Testing Performed

  1. yarn lint in ui
  2. yarn build in ui
  3. wc build/static/js/*.js in ui
    • branch - master: -188 = 11083100 - 11083288 because replace object properties with literal strings

@roxbot
Copy link
Contributor

roxbot commented Nov 20, 2022

Images are ready for the commit at 036998b.

To use with deploy scripts, first export MAIN_IMAGE_TAG=3.73.x-23-g036998b0f7.

Copy link
Contributor

@dvail dvail left a comment

Choose a reason for hiding this comment

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

Ah it looks like TypeScript inferred useState(wizardSteps.FORM) to be useState<'FORM'>(wizardSteps.FORM), when on 4.8 it was string. Interesting I wonder if that has to do with an inference change from one of the first few release notes.

@pedrottimark
Copy link
Contributor Author

Yes, although difficult to say which change caused TypeScript to check more carefully, it is a helpful error report.

I was pleasantly surprised only one such error.

@pedrottimark pedrottimark merged commit 1854292 into master Nov 21, 2022
@pedrottimark pedrottimark deleted the ui-devDependencies-typescript-4.9.3 branch November 21, 2022 13:45
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.

None yet

3 participants