Closed
Description
Bug Report
π Search Terms
key remapping tuples mapped types
π Version & Regression Information
Typescript 4.1
- I was unable to test this on prior versions because Typescript 4.1 introduced key remapping
β― Playground Link
Playground link with relevant code
π» Code
type NoBoolean<K, T> = T extends boolean ? never : K
type FilterBooleans<T> = {
[K in keyof T as NoBoolean<K, T[K]>]: T[K]
}
type Filtered = FilterBooleans<[string, boolean, number, boolean]>
// should only accept ["1", 3]
const f: Filtered = ["1", true, 3, false]
type Length = Filtered["length"];
// should only accept 2, not 4
const l: Length = 4;
π Actual behavior
#26063 introduced mapped type support for arrays and tuples. This breaks when using the new "key remapping" feature added to TypeScript 4.1
. A record
type is produced that looks like a tuple
, rather than the tuple
type that would be produced when not using as
to remap keys.
π Expected behavior
A filtered tuple type should be produced.
Metadata
Metadata
Assignees
Labels
No labels