我是React和TypeScript的新手,所以可能會有一些顯而易見的錯誤。我試圖做到以下幾點:React TypeScript屬性'assign'在類型'Object constructor'上不存在
const props = Object.assign({}, this.props, {
loaded: this.state.loaded
});
我在.tsx
文件中得到這個錯誤:Property 'assign' does not exist on type 'Object constructor'.
發現this thread和嘗試:
const props = (<any>Object).assign({}, this.props, {
loaded: this.state.loaded
});
給了我這個錯誤:Property 'any' does not exist on type 'JXS.IntrinsicElements'.
我也試過這個返回Unexpected modifier
申報。
declare interface ObjectConstructor {
assign(target: any, ...sources: any[]): any;
}
我錯過了什麼?
這有點奇怪。你可以提供更多的背景嗎?例如。你使用它的組件,也可能是你的'tsconfig'?因爲第一個代碼片段不應該有問題。 –