Following a guide on implementing ControlValueAccessor , I noticed that the propagating function passed in the implementation of registerOnChange
seems a bit loose.
(在遵循有关实现ControlValueAccessor的指南之后,我注意到在registerOnChange
的实现中传递的传播函数似乎有点松动。)
private propagateChange = (_: any) => { };
public registerOnChange(fn: any) {
this.propagateChange = fn;
}
I'm curious why the parameter passed in is any
instead of something more strict describing an actual function (let alone a function with a predetermined signature).
(我很好奇为什么传入的参数是any
参数,而不是更严格地描述实际函数的参数(更不用说具有预定签名的函数了)。)
After all, that's something that will be provided by the framework so it's predictable as to its contents, isn't it? (毕竟,框架会提供某些内容,因此可以预测其内容,不是吗?)
Intuitively, I expected something type-restricted like this, instead.
(凭直觉,我期望这样的类型受限制 。)
public registerOnChange(fn: () => void) {
this.propagateChange = fn;
}
Or, possibly, (with any
preferably substituted for something more specific too).
(或者,可能的是(也最好用any
代替更具体的东西)。)
public registerOnChange(fn: (param: any) => void) {
this.propagateChange = fn;
}
Why isn't that the case in Angular?
(为什么在Angular中不是这种情况?)
Sloppy relaxing in design or a deeper issue I'm not seeing? (草率的放松设计或我没有看到的更深层次的问题?)
ask by Konrad Viltersten translate from so 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…