You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
typeSubGuard<A,Xextends[A]>=X;typeIsSub<Mextendsany[],Sextendsany[]>=Mextends[
...SubGuard<M[number], infer B>,
...S,
...any[]]
? B
: never;typeE0=IsSub<[1,2,3,4],[2,3,4]>;// Evaluated: type E0 = [1, 2, 3, 4] extends [...infer B, 2, 3, 4, ...any[]] ? B : nevertypeE1=[1,2,3,4]extends[...infer B,2,3,4, ...any[]] ? B : never;// type E1 = unknown[]declareletv0: E0;declareletv1: E1;declareletv2: unknown[];v0=v1=v2=v1;// ^ Type 'unknown[]' is not assignable to type 'IsSub<[1, 2, 3, 4], [2, 3, 4]>'.(2322)v1=v2=v0;// Ok
π Actual behavior
The generic type being provided with correct parameters IsSub<[1, 2, 3, 4], [2, 3, 4]> appears to get evaluated into a conditianal type literal [1, 2, 3, 4] extends [...infer B, 2, 3, 4, ...any[]] ? B : never
π Expected behavior
If such a generic has an error in syntax or faces some limitation in the use, the compiler should raise an exception. If it is correct (it looks correct) it must be evaluated into a definitive type, e.g. unknown[]. In contrast, if we change generic:
typeIsSub<Mextendsany[],Sextendsany[]>=Mextends[
...SubGuard<M[number], infer B>,
...S]
? B
: never;
it gives us:
typeE0=IsSub<[1,2,3,4],[2,3,4]>;// Evaluated: type E0 = [1]
that is expected.
One more inconsistency in the example:
If we add:
declareletv3: never;v3=v0;
the compiler shows an error:
Type 'IsSub<[1, 2, 3, 4], [2, 3, 4]>' is not assignable to type 'never'.
Type '[M[number]]' is not assignable to type 'never'.(2322)
where we can see type [M[number]] which is absurd since M is not in the context and is the name of a variable in the original generic type IsSub<M extends any[], S extends any[]>.
If we substitute M with [1, 2, 3, 4] it still does not answer what actual type we have:
declareletv4: [[1,2,3,4][number]];v0=v4;// Errorv4=v0;// Ok
It's definitely wrong that E0 remains a deferred conditional type. Looks like a combined type mapper we're creating in getConditionalType isn't properly instantiating [M[number]] into [1 | 2 | 3 | 4].
Bug Report
π Search Terms
generic conditional type inference not evaluated
π Version & Regression Information
β― Playground Link
Playground link with relevant code
π» Code
π Actual behavior
The generic type being provided with correct parameters
IsSub<[1, 2, 3, 4], [2, 3, 4]>
appears to get evaluated into a conditianal type literal[1, 2, 3, 4] extends [...infer B, 2, 3, 4, ...any[]] ? B : never
π Expected behavior
If such a generic has an error in syntax or faces some limitation in the use, the compiler should raise an exception. If it is correct (it looks correct) it must be evaluated into a definitive type, e.g.
unknown[]
. In contrast, if we change generic:it gives us:
that is expected.
One more inconsistency in the example:
If we add:
the compiler shows an error:
where we can see type
[M[number]]
which is absurd sinceM
is not in the context and is the name of a variable in the original generictype IsSub<M extends any[], S extends any[]>
.If we substitute
M
with[1, 2, 3, 4]
it still does not answer what actual type we have:Playground
The text was updated successfully, but these errors were encountered: