left click
left click

Reputation: 894

Is there any way to list types of interface's properties?

interface Inter {
    a: number;
    b: string;
}

let variable:(blabla);
             => right here.

I want to set the above to (number | string) using Inter's properties. Is there any way to do this? Thanks for reading !

Upvotes: 0

Views: 64

Answers (2)

Titian Cernicova-Dragomir
Titian Cernicova-Dragomir

Reputation: 250186

You can use a type query with a type that is a union of all keys, which you can get keyof:

let val: Inter[keyof Inter]; // will be string | number

Upvotes: 3

Lia
Lia

Reputation: 11982

try:

let val: typeon Inter.a | val: typeon Inter.b

Upvotes: 0

Related Questions