1type Data = {
2 value: number;
3 text: string;
4};
5type textProperty = Data["text"]; //string
6
7//OR
8const data = {
9 value: 123,
10 text: 'hello'
11};
12type textProperty = typeof data["text"]; //string
1declare function create(o: object | null): void;
2// OKcreate({ prop: 0 });create(null);create(undefined); // with `--strictNullChecks` flag enabled, undefined is not a subtype of nullArgument of type 'undefined' is not assignable to parameter of type 'object | null'.2345Argument of type 'undefined' is not assignable to parameter of type 'object | null'.
3create(42);Argument of type '42' is not assignable to parameter of type 'object | null'.2345Argument of type '42' is not assignable to parameter of type 'object | null'.create("string");Argument of type '"string"' is not assignable to parameter of type 'object | null'.2345Argument of type '"string"' is not assignable to parameter of type 'object | null'.create(false);Argument of type 'false' is not assignable to parameter of type 'object | null'.2345Argument of type 'false' is not assignable to parameter of type 'object | null'.Try
1const data = {
2 value: 123,
3 text: 'text'
4};
5type Data = typeof data["text"]; // String