Extending a generic parameter in Typescript

前端 未结 2 1195
醉梦人生
醉梦人生 2020-12-21 03:52

I want to create a utility function which creates a checklist by adding an isChecked knockout observable property to each item in an array. This function should

2条回答
  •  轮回少年
    2020-12-21 04:13

    There isn't a way to express this in TypeScript.

    You can obviously do this instead:

    interface CheckListItem {
        isChecked: KnockoutObservable;
        item: T;
    }
    

    This has the advantage of not breaking the object when it happens to have its own isChecked property.

提交回复
热议问题