Closed
Description
TypeScript Version: 2.5.3
Would it be possible to have something like the keyof
operator for arrays? The operator would be able to access the values in the array.
Code
With object we can do the following:
const obj = {one: 1, two: 2}
type Prop = {
[k in keyof typeof obj]?: string;
}
function test(p: Prop) {
return p;
}
test({three: '3'}) // throws an error
Could we do something like the following with arrays?
const arr = ['one', 'two'];
type Prop = {
[k in valuesof arr]?: string;
}
function test(p: Prop) {
return p;
}
test({three: '3'}) // throws an error
Metadata
Metadata
Assignees
Labels
No labels