-
Notifications
You must be signed in to change notification settings - Fork 12.9k
Closed
Labels
Working as IntendedThe behavior described is the intended behavior; this is not a bugThe behavior described is the intended behavior; this is not a bug
Description
Bug Report
🔎 Search Terms
extends when infer, lazy evaluation
🕗 Version & Regression Information
- This is the behavior in every version I tried, and I reviewed the FAQ for entries about _________
⏯ Playground Link
Playground link with relevant code
more detail can also see: stackOverflow
💻 Code
type T0 = [IsNegative<-15>, IsNegative<90>]; // [true, false]
type T1 = Sub<-15, 90>; // ["Why?", [true, false]] /* Why [true, false] extends [false, false] ??? */
type T2 = [boolean, boolean] extends [false, false] ? true : false; // true
type T3 = [false, false] extends [boolean, boolean] ? true : false; // false
export type StartsWith<S extends string, SearchString extends string> = S extends `${SearchString}${infer T}` ? true : false;
export type IsNegative<N extends number> = StartsWith<`${N}`, '-'>;
export type Sub<A extends number, B extends number> = [IsNegative<A>, IsNegative<B>] extends infer R
? R extends [false, false]
? ['Why?', R]
: 'Expected'
: never;
export type Sub1<A extends number, B extends number> = [IsNegative<A>, IsNegative<B>] extends infer R
? [false, false] extends R
? ['Why?', R]
: 'Expected'
: never;
export type Sub2<A extends number, B extends number> = [IsNegative<A>, IsNegative<B>] extends [false, false]
? ['Why?',]
: 'Expected'
export type Sub3<A extends number, B extends number> = [IsNegative<A>, IsNegative<B>][number] extends false
? ['Why?',]
: 'Expected'
type T0 = [IsNegative<-15>, IsNegative<90>]; // [true, false]
type T1 = Sub<-15, 90>; // ["Why?", [true, false]] /* Why [true, false] extends [false, false] ??? */
type T2 = Sub1<-15, 90>; // Expected /* Work well */
type T3 = Sub2<-15, 90>; // ['Why?] /* Can't work too */
type T4 = Sub3<-15, 90>; // Expected /* Work well */
🙁 Actual behavior
type T1 = ["Why?", [true, false]]'
🙂 Expected behavior
type T1 = 'Expected'
(Same as T2)
Metadata
Metadata
Assignees
Labels
Working as IntendedThe behavior described is the intended behavior; this is not a bugThe behavior described is the intended behavior; this is not a bug