-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Description
Bug Report
π Search Terms
- 5.1
- tuple
- array
- spread
Possibly related:
- Comparing a tuple input to a variadic tuple no longer narrows itΒ #54048
- Tuple with optional element and exactOptionalPropertyTypes still returns undefined during iterationΒ #54302
π Version & Regression Information
- This changed between versions v5.0.4 and v5.1.3
β― Playground Link
I was unable to reproduce: if you could please steer me in the right direction I'm happy to dig more, but I'm a bit stuck on how to debug this
π» Code
We have an issue using io-ts. If this is a bug with that library, I'll close this here, but I don't think it is.
The TypeScript compiler is complaining about a number of excerpts from the d.ts file, where the compiler doesn't seem to be making sense.
Here's an example error:
node_modules/io-ts/lib/index.d.ts:1151:24 - error TS2344: Type 'CS' does not satisfy the constraint '[Mixed, Mixed, Mixed[]]'.
Type '[Mixed, Mixed, ...Mixed[]]' is not assignable to type '[Mixed, Mixed, Mixed[]]'.
Target allows only 3 element(s) but source may have more.
1151 ) => TaggedUnionC<Tag, CS>
The code it's referring to is here:
export interface TaggedUnionC<Tag extends string, CS extends [Mixed, Mixed, ...Array<Mixed>]>
extends TaggedUnionType<Tag, CS, TypeOf<CS[number]>, OutputOf<CS[number]>, unknown> {}
export declare const taggedUnion: <Tag extends string, CS extends [Mixed, Mixed, ...Mixed[]]>(
tag: Tag,
codecs: CS,
name?: string
) => TaggedUnionC<Tag, CS>As you can see, the compiler seems to be collapsing the [Mixed, Mixed, ...Array<Mixed>] to [Mixed, Mixed, Mixed[]], which is incorrect. It then doesn't like CS extending [Mixed, Mixed, ...Mixed[]], which it considers incompatible with its incorrect collapsing.
Weirdly, if I tweak the d.ts file by hand, the error goes away:
- export interface TaggedUnionC<Tag extends string, CS extends [Mixed, Mixed, ...Array<Mixed>]>
+ export interface TaggedUnionC<Tag extends string, CS extends [Mixed, Mixed, ...Mixed[]]>π Actual behavior
Compilation errors
π Expected behavior
Successful compilation