Slide 3
Slide 3 text
Getting the type of a single key in an object
Use the index operator.
type Obj = {
0: 'a',
1: 'b',
prop0: 'c',
prop1: 'd',
};
// %inferred-type: "c"
type Result0 = Obj['prop0'];
// %inferred-type: "a" | "b"
type Result1 = Obj[0 | 1];
// %inferred-type: "c" | "d"
type Result2 = Obj['prop0' | 'prop1'];