Closed as not planned
Description
π Search Terms
literal intersection infer extract value
π Version & Regression Information
Behavior changed since 5.1
β― Playground Link
π» Code
type R1 = number extends number ? true : false // true
type R2 = 1 extends 1 ? true : false // true
type R3 = 1 extends number ? true : false // true
type R4 = number & { a: 1 } extends number ? true : false // true
type R5 = number & { a: 1 } extends number & infer U ? U : never // { a: 1 }
type R6 = 1 & { a: 1 } extends 1 & infer U ? U : never // { a: 1 }
type R7 = 1 & { a: 1 } extends number & infer U ? U : never // 1 & { a: 1 }
π Actual behavior
see above
π Expected behavior
R7
should returns { a: 1 }
as 1 extends number
.
Due to this and #54648 (comment),
currently it doesn't seem to have a way to write the IsNegative
type (among others) anymore.
This is one of the problems caused by #54648. It would be great if that can be re-evaluated.
Additional information about the issue
tbh, IMO many types I wrote in type-plus would be best provided by TS itself to make the type system more predictable and enable us to write better types. One suggestion is to support typeof T
for types, but that's a different topic.