Typescript generics extending class and interface

后端 未结 3 687
我寻月下人不归
我寻月下人不归 2020-12-15 06:44

I have a Typescript class which includes a generic which needs to extend another class and implement an interface. Here is an example

interface IHasImage {
          


        
3条回答
  •  忘掉有多难
    2020-12-15 07:15

    It looks like this is the only way of doing it that I can find. Not perfectly clean but it does the right thing.

    interface IHasImage extends Model{  
      imageUrl():string; 
    }
    
    class Model {
    }
    
    class View {
    }
    

    Here is a screenshot from the playground verifying that it works:

    playground

    Edit: Added correct workaround.

提交回复
热议问题