Skip to content

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

Description

@MajorLift

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

  • Example:
typeType=number|Date| ...
letvalue: Typeif(typeofvalue==='number'||valueinstanceofDate){// Type of 'value' is not `number | Date`, but `(Type & number) | (Type & Date)`.}
  • Error:
TypeScriptError: Failedtoinitialisetheproject.src/structs/refinements.ts:165:10-errorTS2365: Operator'<='cannotbeappliedtotypes'number'and'(Type & number) | (Type & Date)'.165(minimum<=value&&value<=maximum)||~~~~~~~~~~~~~~~~src/structs/refinements.ts:165:30-errorTS2365: Operator'<='cannotbeappliedtotypes'(Type & number) | (Type & Date)'and'number'.165(minimum<=value&&value<=maximum)||~~~~~~~~~~~~~~~~atgetProgram(file:///Volumes/Code/metamask/superstruct/node_modules/@ts-bridge/cli/dist/build.js:36:15)atbuildHandler(file:///Volumes/Code/metamask/superstruct/node_modules/@ts-bridge/cli/dist/build.js:69:21)atObject.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:8993atj(/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)atte.parse(/Volumes/Code/metamask/superstruct/node_modules/yargs/build/index.cjs:1:40478)

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions