热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

错误TS2339:“响应”类型上不存在属性“结果”-errorTS2339:Property'results'doesnotexistontype'Response'

Ifollowedapieceofcodebuildingandappthatcollectdatafromlast.fmusingangular2,typescrip

I followed a piece of code building and app that collect data from last.fm using angular2, typescript and firebase.

我跟着一段代码构建和应用程序,使用angular2,typescript和firebase从last.fm收集数据。

the source code can be found here: https://github.com/vtts/mytunes

源代码可以在这里找到:https://github.com/vtts/mytunes

QUESTION how can I cast the results from the json calls?

问题如何从json调用中转换结果?

Source code on github

https://github.com/vtts/mytunes/blob/master/app/music/services/music.srv.ts

https://github.com/vtts/mytunes/blob/master/app/music/services/music.srv.ts

I receive the following errors:

app/music/services/music.service.ts(29,39): error TS2339: Property 'results' does not exist on type 'Response'. 
app/music/services/music.service.ts(51,36): error TS2339: Property 'album' does not exist on type 'Response'.

package.json

{
  "name": "mytunes",
  "version": "1.0.0",
  "scripts": {
    "start": "tsc && concurrently \"npm run tsc:w\" \"npm run lite\" ",
    "lite": "lite-server",
    "postinstall": "typings install",
    "tsc": "tsc",
    "tsc:w": "tsc -w",
    "typings": "typings"
  },
  "license": "ISC",
  "dependencies": {
    "angular2": "2.0.0-beta.15",
    "bootstrap": "^3.3.6",
    "es6-shim": "^0.35.0",
    "firebase": "^2.4.2",
    "reflect-metadata": "0.1.2",
    "rxjs": "5.0.0-beta.2",
    "systemjs": "0.19.26",
    "zone.js": "0.6.10"
  },
  "devDependencies": {
    "concurrently": "^2.0.0",
    "lite-server": "^2.2.0",
    "typescript": "^1.8.10",
    "typings": "^0.7.12"
  }
}

tsconfig.json

{
    "compilerOptions": {
        "target": "es5",
        "module": "system",
        "moduleResolution": "node",
        "sourceMap": true,
        "emitDecoratorMetadata": true,
        "experimentalDecorators": true,
        "removeComments": false,
        "noImplicitAny": false,
        "outDir": "js"
    },
    "exclude": [
        "node_modules",
        "typings/main",
        "typings/main.d.ts"
    ]
}

Last.fm REST API

I am using the following REST APIs:

我使用以下REST API:

  • http://www.last.fm/api/show/album.search
  • http://www.last.fm/api/show/album.search
  • http://www.last.fm/api/scrobbling
  • http://www.last.fm/api/scrobbling

1 个解决方案

#1


2  

Instead of reusing the variable res which is typed as Response

而不是重用输入为Response的变量res

res = res.json();

create a new one

创造一个新的

let result = res.json();

and then use result for the following lines instead of res

然后使用结果为以下行而不是res


推荐阅读
author-avatar
孙亦然5277
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有