error TS2339: Property 'results' does not exist on type 'Response'
Asked Answered
A

1

6

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

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

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

Source code on github

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:

Angelo answered 25/4, 2016 at 14:29 Comment(2)
Looks like the problem is in this line github.com/vtts/mytunes/blob/… Try printing res to console and check whether it actually has a results key.Livi
dear @GünterZöchbauer, I can't even run the application because the compilation failsAngelo
J
8

Instead of reusing the variable res which is typed as Response

res = res.json();

create a new one

let result = res.json();

and then use result for the following lines instead of res

Judiciary answered 25/4, 2016 at 14:58 Comment(3)
Dear @GünterZöchbauer your proposal is already in place in the the line 29 and the same issue occurs too.Angelo
Then delete line 27 and put 29 on its place.Livi
obviously, you are right, I was debugging for too long this piece of code. Many ThanksAngelo

© 2022 - 2024 — McMap. All rights reserved.