export const OBJECT = { FOO: 'foo', } as const; export type TObjectKey = keyof typeof OBJECT; export type TObjectValue = (typeof OBJECT)[TObjectKey];const myObj = { a: 1, b: 'some_string' } as const; type values = typeof myObj[keyof typeof myObj]; // values = 1 | 'some_string'type Data = { value: number; text: string; }; type textProperty = Data["text"]; //string //OR const data = { value: 123, text: 'hello' }; type textProperty = typeof data["text"]; //stringfunction isFish(pet: Fish | Bird): pet is Fish { return (<Fish>pet).swim !== undefined; } // Both calls to 'swim' and 'fly' are now okay. if (isFish(pet)) { pet.swim(); } else { pet.fly(); }