Value-based dynamic interface of an object (Typescript)

Asked

Viewed 97 times

0

I’m trying to accomplish the following:

interface A {
    name: string,
    type: string
}

let var_A: Array<A> = [
    {name: 'firstName', type: 'string'},
    {name: 'lastName',  type: 'string'},
    {name: 'age',       type: 'number'}
]

interface B {
    firstName: string,
    lastname: string,
    age: number
}

let var_B: Array<B> = [
    {firstName: 'José', lastname: 'Silva', age: 25},
    {firstName: 'Pedro', lastname: 'Paulo', age: 50},
]

My big problem is: how to create the B interface dynamically, based on the var_A object? Is it possible?

  • A dynamic interface? Why do you need to do this?

  • To see if you can do.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.