[英]Class implements interface, but the arguments to a method of a member variable have no type?
So let's just look at my code. 因此,让我们看一下我的代码。 It's not very well described.
描述不是很好。
This is interface: 这是接口:
interface IModel<T = any> {
effects: {
[key: string]: (getState: () => T) => void;
};
}
interface IState {
name: string;
age: number;
}
This is wrong, but I don't know why: 这是错误的,但我不知道为什么:
class Model implements IModel<IState> {
effects = {
getName: (getState) => {
const { /** Here, Ts has no smart tips */ } = getState();
}
};
}
Need me to add type, just can have tips: 需要我添加类型,只需提示即可:
class Model implements IModel<IState> {
effects = {
getName: (getState: () => IState) => { // add type
const { /** Yes, have 'name' and 'age' */ } = getState();
}
};
}
But, I think the latter approach is a bit verbose. 但是,我认为后一种方法有点冗长。
Unfortunately you can't do this. 不幸的是你不能这样做。 Check https://github.com/Microsoft/TypeScript/issues/1373 for updates.
检查https://github.com/Microsoft/TypeScript/issues/1373以获取更新。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.