无论如何,是否有简明扼要地表明/承诺一个地方的类型应该与其他地方的另一种类型并行缩小(不必求助于泛型或额外的强制转换)?
例如
class C{
get prop():any{
return 0 // or something else ofc.
}
indirectProp(){
//...
return {
//...
ref:this.prop
}
}
}
let c = new C();
if(c.prop instanceof Number){
c.prop // Number
c.indirectProp().ref // any; Would like to either indicate to TS that ref's type should also be narrowed or that apparent contingencies like this should be respected throughout.
}