Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Q25. Typescript报错:接口只能扩展使用静态已知成员的对象类型或对象类型的交集。ts(2312) #28

Open
lstoryc opened this issue Aug 5, 2020 · 1 comment

Comments

@lstoryc
Copy link
Owner

lstoryc commented Aug 5, 2020

image

类或接口只能扩展对象类型或对象类型与静态已知成员的交集,因为编译器需要检查类或接口中声明的属性类型是否与基类型的相应属性(如果有)的类型兼容。

@lstoryc
Copy link
Owner Author

lstoryc commented Aug 5, 2020

解决方法是使用交叉点类型而不是子接口:

interface ITreeDataExtend {
  preIcon?: string;
}

export type TTreeNodeActionData<T> = T & ITreeDataExtend;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant