外推缩小类型

问题描述

无论如何要简明地表明/承诺一个地方的类型应该与其他地方的另一种类型并行缩小(而不必求助于泛型或额外的转换)?

例如

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.
}

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)