我在我的应用程序中使用TypeScript,在那里我使用函数:
Object.assign(this.success, success.json())
Run Code Online (Sandbox Code Playgroud)
但是,在编译期间,我收到以下错误:
error TS2339: Property 'assign' does not exist on type 'ObjectConstructor'.
Run Code Online (Sandbox Code Playgroud)
你知道我怎么能摆脱这个错误?
我正在研究ng2实现.我正在使用以下函数调用将对象转换为数组:
var authors = Object.entries(responseObject.Authors);
Run Code Online (Sandbox Code Playgroud)
这是标准的js功能.但是,ts编译器返回以下错误:
"Property 'entries' does not exist on type 'ObjectConstructor'"
Run Code Online (Sandbox Code Playgroud)
基于快速谷歌,似乎解决方案可能是将compilerOptions目标属性从es5更改为es6.但是,在之前的一个问题的一些先前的研究之后,我认为我能够通过在我的tsconfig.json上包含额外的"lib"属性来利用es6功能:
"compilerOptions": {
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"module": "commonjs",
"noEmitOnError": true,
"noImplicitAny": false,
"outDir": "../Scripts/",
"removeComments": false,
"sourceMap": true,
"target": "es5",
"moduleResolution": "node",
"lib": [
"es2015",
"dom"
]
}
Run Code Online (Sandbox Code Playgroud)
我也尝试将目标属性更改为es2015,然后重建项目并执行"typescriptUsingTsConfig",但我仍然得到相同的错误.知道我可以在这里做什么来利用Object.entries()函数?
我在项目中使用angularjs.
我从服务器获取了一系列对象.每个对象包含很少的属性,其中一个属性是date属性.
这是我从服务器获得的数组(在json中):
[
{
"Address": 25,
"AlertType": 1,
"Area": "North",
"MeasureDate": "2019-02-01T00:01:01.001Z",
"MeasureValue": -1
},
{
"Address": 26,
"AlertType": 1,
"Area": "West",
"MeasureDate": "2016-04-12T15:13:11.733Z",
"MeasureValue": -1
},
{
"Address": 25,
"AlertType": 1,
"Area": "North",
"MeasureDate": "2017-02-01T00:01:01.001Z",
"MeasureValue": -1
}
.
.
.
]
Run Code Online (Sandbox Code Playgroud)
我需要从阵列中获取最新日期.
从对象数组中获取最新日期的优雅方法是什么?
我正在使用 object.entries 方法将一些 JSON 对象数据推送到数组中...它正在工作,现在我收到错误:
类型“ObjectConstructor”上不存在属性“entries”。
我通过查看类似问题了解到,这可能是因为我使用的打字稿版本不支持条目方法,但是有其他选择吗?由于我是打字稿的新手,因此我对更改版本等感到不舒服。
Object.entries(data).forEach(([key, value]) => {
this.array.push ({
id: key,
name: value.name,
desc: value.desc})
});
Run Code Online (Sandbox Code Playgroud)
感谢您的任何意见/帮助:)