There is Props interface from third-party:
interface Props {
id: string;
name: string;
age: number;
approval: Approval
}
interface Approval {
signature: string;
}
What is the solution that Props convert to array:
[
{
name: 'id',
type: 'string'
},
{
name: 'name',
type:'string'
},
{
name: 'age',
type: 'number'
},
{
name: 'approval',
type: 'Approval'
}
]
I have no idea that Typescript's interface can do this?
Update: Maybe it is not 'convert', somehow it just like 'reflect' or something else. Can I do this in babel?
However, I just want to get this array by Props.
Propsitems, since they are all missing the mandatory attributesageandapproval.PropsorApprovalwill exist at runtime for you to turn into an array. There is no reflection in TypeScript. You can either add a build step to do reflection, or you can refactor to write your array and generate types from it. The various options are described in answers to this question. Does that fully address the question, or am I missing something?