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

Regression from TypeScript v5.0: change in type narrowing behavior #19

Open
MajorLift opened this issue May 21, 2024 · 0 comments
Open
Labels
bug Something isn't working team-wallet-framework

Comments

@MajorLift
Copy link

MajorLift commented May 21, 2024

A regression is introduced by upgrading TypeScript to v5.0. This is caused by a breaking change in TypeScript's type narrowing behavior.

  • Example:
type Type = number | Date | ...
let value: Type

if (typeof value === 'number' || value instanceof Date) {
  // Type of 'value' is not `number | Date`, but `(Type & number) | (Type & Date)`.
}
  • Error:
TypeScriptError: Failed to initialise the project.
src/structs/refinements.ts:165:10 - error TS2365: Operator '<=' cannot be applied to types 'number' and '(Type & number) | (Type & Date)'.

165         (minimum <= value && value <= maximum) ||
             ~~~~~~~~~~~~~~~~
src/structs/refinements.ts:165:30 - error TS2365: Operator '<=' cannot be applied to types '(Type & number) | (Type & Date)' and 'number'.

165         (minimum <= value && value <= maximum) ||
                                 ~~~~~~~~~~~~~~~~

    at getProgram (file:///Volumes/Code/metamask/superstruct/node_modules/@ts-bridge/cli/dist/build.js:36:15)
    at buildHandler (file:///Volumes/Code/metamask/superstruct/node_modules/@ts-bridge/cli/dist/build.js:69:21)
    at Object.handler (file:///Volumes/Code/metamask/superstruct/node_modules/@ts-bridge/cli/dist/cli.js:53:16)
    at /Volumes/Code/metamask/superstruct/node_modules/yargs/build/index.cjs:1:8993
    at j (/Volumes/Code/metamask/superstruct/node_modules/yargs/build/index.cjs:1:4956)
    at _.handleValidationAndGetResult (/Volumes/Code/metamask/superstruct/node_modules/yargs/build/index.cjs:1:8962)
    at _.applyMiddlewareAndGetResult (/Volumes/Code/metamask/superstruct/node_modules/yargs/build/index.cjs:1:9604)
    at _.runCommand (/Volumes/Code/metamask/superstruct/node_modules/yargs/build/index.cjs:1:7231)
    at [runYargsParserAndExecuteCommands] (/Volumes/Code/metamask/superstruct/node_modules/yargs/build/index.cjs:1:58912)
    at te.parse (/Volumes/Code/metamask/superstruct/node_modules/yargs/build/index.cjs:1:40478)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working team-wallet-framework
Projects
None yet
Development

No branches or pull requests

1 participant