-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Closed
Labels
QuestionAn issue which isn't directly actionable in codeAn issue which isn't directly actionable in code
Description
TypeScript Version: 3.9.0
Search Terms:
mapped type tuple object keys
union of keys of all objects in a tuple
Code
type A = [{
b: 'b'
}, {
a: 'a',
}];
type B = {
[i in Extract<keyof A, number>]: keyof A[i];
}[Extract<keyof A, number>];
function b(b: B) {
b // is type never, should be "a" | "b"
}My thinking:
{ [i in Extract<keyof A, number>]: keyof A[i]; }
// should map to
["a", "b"]
// so indexing that resulting tuple
[Extract<keyof A, number>]
// should return
"a" | "b"Can be worked around by hard coding expected tuple lengths ...
type Indices = 0 | 1 | 2 ...;
type B = {
[i in Indices]: keyof A[i];
}[Indices];Expected behavior:
I would like to extract a union of all the keys found in any of the objects in a tuple. It should return "a" | "b", not never.
Actual behavior:
type B is never.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
QuestionAn issue which isn't directly actionable in codeAn issue which isn't directly actionable in code