zl程序教程

您现在的位置是:首页 >  其它

当前栏目

Initializer provides no value for this binding element and the binding element has no default value

for The and No value this has Element
2023-09-14 09:02:58 时间

引起错误的TypeScript代码:

test(){
    const a = () => ({ a , b = 2 } = {}): number => 11;
  }

该编译错误的解决方法1

test(){
    const a = () => ({ a , b = 2 }:any = {}): number => 11;
  }

解法2

test(){
    const a = () => ({ a = 1, b = 2 } = {}): number => 11;
  }

解法3

 test(){
    const fun = () => ({ a , b } = { a: 1, b: 2}): number => 11;
  }

参考:https://stackoverflow.com/questions/57527710/how-to-fix-initializer-provides-no-value-for-this-binding-element-and-the-bindi