Bug Report
🔎 Search Terms
- extends constraint inferred rest
- multiple inferred rest types
🕗 Version & Regression Information
Version 4.7 and higher (including nightly)
- This is the behavior in every version I tried, and I reviewed the FAQ
⏯ Playground Link
TypeScript playground
💻 Code
typePrefix<A>=Aextends[...infer Pextends0[],1] ? {p: P} : never{typeTest=Prefix<[0,0,1]>}// type Test = {p: [0, 0]}{typeTest=Prefix<[0,0,1,1]>}// type Test = nevertypePrefixSuffix<A>=Aextends[...infer Pextends0[],1, ...infer Sextends0[]] ? {p: P,s: S} : never{typeTest=PrefixSuffix<[0,0,1,0,0]>}// type Test = {p: 0[], s: 0[]}{typeUnexpected=PrefixSuffix<[0,0,1,1,0,0]>}// type Unexpected = {p: 0[], s: 0[]}🙁 Actual behavior
Similar to Prefix, which extracts a tuple of leading zeroes and works as expected, I tried to construct PrefixSuffix, to extract both the leading and trailing zeroes. When applied to an array with multiple ones, PrefixSuffix<[0,0,1,1,0,0]> evaluates to {p: 0[], s: 0[]} instead of never.
🙂 Expected behavior
I would have expected PrefixSuffix<[0,0,1,1,0,0]> to evaluate to never, as [0,0,1,1,0,0] cannot extend an array that contains only a single 1. I also would have expected PrefixSuffix<[0,0,1,0,0]> to infer tuple types {p: [0,0], s: [0,0]} rather than {p: 0[], s: 0[]}, but maybe that's just a design limitation.
Bug Report
🔎 Search Terms
🕗 Version & Regression Information
Version 4.7 and higher (including nightly)
⏯ Playground Link
TypeScript playground
💻 Code
🙁 Actual behavior
Similar to
Prefix, which extracts a tuple of leading zeroes and works as expected, I tried to constructPrefixSuffix, to extract both the leading and trailing zeroes. When applied to an array with multiple ones,PrefixSuffix<[0,0,1,1,0,0]>evaluates to{p: 0[], s: 0[]}instead ofnever.🙂 Expected behavior
I would have expected
PrefixSuffix<[0,0,1,1,0,0]>to evaluate tonever, as[0,0,1,1,0,0]cannot extend an array that contains only a single1. I also would have expectedPrefixSuffix<[0,0,1,0,0]>to infer tuple types{p: [0,0], s: [0,0]}rather than{p: 0[], s: 0[]}, but maybe that's just a design limitation.