Closed
Description
π Search Terms
named tuple (label:bug)
π Version & Regression Information
- This was introduced in 5.2.2 as prior versions would discard the element names
β― Playground Link
π» Code
interface MultiKeyMap<Keys extends readonly unknown[], Value> {
get<Key extends GetKeys<Keys>>(...key: Key): GetResult<Keys, Key, Value>
}
type GetKeys<Keys extends readonly unknown[]> = Keys extends [...infer Remain, infer _]
? Keys | GetKeys<Remain>
: Keys;
type GetResult<Id extends readonly unknown[], Args extends GetKeys<Id>, Value> = Args extends Id
? Value | undefined
: Id extends [...Args, ...infer Rest]
? Iterable<[...Rest, Value]>
: never;
const x: MultiKeyMap<[id1: string, id2: string], object> = null!;
const id1 = 'abc' as string;
const matches = x.get(id1);
π Actual behavior
typeof matches = Iterable<[string, id2: object]>
π Expected behavior
typeof matches = Iterable<[id2: string, object]>
Additional information about the issue
There are a few bits to this bug which I wasnt able to remove from the example. I tried simplifiying it as much as I could, but any further changes I made would result in the bug disappearing and the correct labels being shown. If I had to hazard a guess, I would assume its something relating to this chunk:
Id extends [...Args, ...infer Rest]
? Iterable<[...Rest, Value]>
The index of the label captured by the ...infer Rest
isnt reduced by the length of Args
, so it ends up on element 1 of [...Rest, Value]
rather than element 0