Closed as not planned
Description
π Search Terms
regression, type parameter, 5.4
π Version & Regression Information
- This is a crash
- This changed between versions 5.3.3 and 5.4.2
β― Playground Link
π» Code
This is the simplified code
type AssignResult<Arr extends object[]> = Arr
// [null, number, undefined, string] => [number, string]
type Filter<Arr, ToOmit> = Arr extends [infer Head, ...infer Tail]
? Head extends ToOmit
? Filter<Tail, ToOmit>
: [Head, ...Filter<Tail, ToOmit>]
: [];
type WorksPrior54<S extends object | null> = AssignResult<Filter<S, null>>
type Works = AssignResult<Filter<object | null, null>>
This is the full code (error message is slightly different, but probably they are the same):
type AssignResult<Arr extends object[]> = Arr extends [...infer Rest extends object[], infer Last]
? {
[K in keyof Last | keyof AssignResult<Rest>]: K extends keyof Last
? Last[K]
: K extends keyof AssignResult<Rest>
? AssignResult<Rest>[K]
: never;
}
: object;
type Filter<Arr, ToOmit> = Arr extends [infer Head, ...infer Tail]
? Head extends ToOmit
? Filter<Tail, ToOmit>
: [Head, ...Filter<Tail, ToOmit>]
: [];
declare function assignByDescriptors<
Target extends object,
// replace the two lines below to make it work with the this line
// Sources extends (object | null | undefined)[],
Source extends object | null | undefined,
Sources extends Source[],
Result extends AssignResult<[Target, ...Filter<Sources, null | undefined>]> = AssignResult<[Target, ...Filter<Sources, null | undefined>]>
>(target: Target, ...sources: Sources): Result
π Actual behavior
I would expect to have no error for 5.4, the same as there was no error before it. Especially considering that there were not breaking changes in 5.4 announcement.
As for the simplified code, there should be no difference between how WorksPrior54
and Works
.
As for the full version of the code, there should be no difference if part of Sources
type parameter is extracted into an intermediate Source
type parameter, or not
π Expected behavior
Error (in the simplified version):
TS2344: Type Filter<S, null> does not satisfy the constraint object[]
Type [] | [unknown] is not assignable to type object[]
Type [unknown] is not assignable to type object[]
Error (in the full version):
TS2344: Type
[Target, ...Filter<Sources, null | undefined>]
does not satisfy the constraint object[]
Type
Target | Filter<Sources, null | undefined>[number]
is not assignable to type object
Type Filter<Sources, null | undefined>[number] is not assignable to type object
Type
(Source extends null | undefined ? [] : [Source])[number] | (Source extends null | undefined ? [] : [Source])[number]
is not assignable to type object
Type
(Source extends null | undefined ? [] : [Source])[number]
is not assignable to type object
Additional information about the issue
No response