Can You Specify Multiple Type Constraints For TypeScript Generics

后端 未结 3 2170
梦如初夏
梦如初夏 2020-12-15 02:28

I have a generic interface like this example with a single type constraint:

export interface IExample {
    getById(id: number): T;
         


        
3条回答
  •  感动是毒
    2020-12-15 02:42

    A work around for this would be to use a super-interface (which also answers the question "why would you allow an interface to inherit from a class").

    interface ISuperInterface extends MyClass, OtherClass {
    
    }
    
    export interface IExample {
        getById(id: number): T;
    }
    

提交回复
热议问题