错误TS2339:类型“功能”上不存在属性“名称”

时间:2018-08-07 18:51:07

标签: typescript

我具有以下功能:

// db can be upcoming_sales or sales_held
// county can be any of the options in the drop down
var data = "db=upcoming_sales&county=Alamance" 

fetch(url, {
    method: "POST"
    headers: {
        "Content-Type": "application/x-www-form-urlencoded",
    },
    body: JSON.stringify(data),
}).then(...)

工作正常。但是,tsc编译器在这一行抱怨:

    constructor(props) {
    super(props);
    this.state = {
      code : "xxx",
    }; 
       this.handleCodex = 
        this.handleCodex.bind(this);
  }

handleCodex(codex){      
  this.setState({
      code: codex,
    });  // this.setState is like a function call. Not a assignment statement.
}


<BlocklyDrawer
      tools={[INICIAR, MOVER, ATACAR]}
      language = {Blockly.Javascript}
      onChange={(code, workspace) => {                       
        this.handleCodex(code);
      }}
      appearance={
        {
          categories: {
            Agente: {
              colour: '160'
            },
          },
        }
      }
    >

说:

  

错误TS2339:类型“函数”上不存在属性“名称”。

是什么原因引起的问题?

1 个答案:

答案 0 :(得分:2)

我能够重现此问题。看起来,为Function定义接口的lib.d.ts文件没有“ name”作为属性。

请参阅Typescript Issue 6623,其中有一种解决方法。

  

接口Function上的name属性在lib.es6.d.ts中定义。如果   您使用--target ES6进行编译时,应该会看到它。

相关问题