Home > other >  How to create a generic from list of interfaces
How to create a generic from list of interfaces

Time:07-18

I have 2 interfaces and AllTypes type:

interface A {
    // ...
}

interface B {
    // ...
}

type AllTypes = A | B;

How can I use a generic to make sure an argument to a function is object with interface A or B?

// pseudocode
function test<T oneof AllTypes>(argument: T): void {
    // ...
}

CodePudding user response:

Try this: <T extends AllTypes>

  • Related