簡體   English   中英

錯誤 TS2339:“響應”類型上不存在屬性“結果”

[英]error TS2339: Property 'results' does not exist on type 'Response'

我遵循了一段代碼構建和應用程序,它使用 angular2、typescript 和 firebase 從 last.fm 收集數據。

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

問題如何從 json 調用中轉換結果?

github上的源代碼

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

我收到以下錯誤:

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'.

包.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"
  }
}

配置文件

{
    "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

我正在使用以下 REST API:

而不是重用類型為Response的變量res

res = res.json();

創建一個新的

let result = res.json();

然后對以下幾行使用result而不是res

Angular 2:“可觀察”類型上不存在錯誤屬性“地圖”<object> '.ts(2339)<div id="text_translate"><p> 我嘗試編寫 function 但不知何故彈出錯誤:當我想要時。map (res =&gt; res.json()); 我在這里做錯了什么? 我使用最新的 Angular 版本。</p><pre> import { Injectable } from '@angular/core'; //import {Http, Headers} from '@angular/http'; import { HttpClient, HttpHeaders } from '@angular/common/http'; import {Contact} from './contact'; import 'rxjs/add/operator/map'; @Injectable({ providedIn: 'root' }) export class ContactService { constructor(private http: HttpClient) { } //retrieving ContactService getContacts() { return this.http.get('http://localhost:3000/api/contacts').map(res =&gt; res.json()); } //add contact method addContact(newContact) { var headers = new HttpHeaders(); headers.append('Content-Type', 'application/json'); return this.http.post('http://localhost:3000/api/contact', newContact, {headers:headers}).map(res =&gt; res.json()); } //delete methods deleteContact(id) { return this.http.delete('http://localhost:3000/api/contact'+ id).map(res =&gt; res.json()); } }</pre></div></object>

[英]Angular 2 : Error Property 'map' does not exist on type 'Observable<Object>'.ts(2339)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

相關問題 錯誤TS2339:類型“對象”上不存在屬性“ json” 錯誤 TS2339:“特殊 []”類型上不存在屬性“默認” 角度:錯誤 TS2339:“對象”類型上不存在“數據”屬性 Angular 2:“可觀察”類型上不存在錯誤屬性“地圖”<object> '.ts(2339)<div id="text_translate"><p> 我嘗試編寫 function 但不知何故彈出錯誤:當我想要時。map (res =&gt; res.json()); 我在這里做錯了什么? 我使用最新的 Angular 版本。</p><pre> import { Injectable } from '@angular/core'; //import {Http, Headers} from '@angular/http'; import { HttpClient, HttpHeaders } from '@angular/common/http'; import {Contact} from './contact'; import 'rxjs/add/operator/map'; @Injectable({ providedIn: 'root' }) export class ContactService { constructor(private http: HttpClient) { } //retrieving ContactService getContacts() { return this.http.get('http://localhost:3000/api/contacts').map(res =&gt; res.json()); } //add contact method addContact(newContact) { var headers = new HttpHeaders(); headers.append('Content-Type', 'application/json'); return this.http.post('http://localhost:3000/api/contact', newContact, {headers:headers}).map(res =&gt; res.json()); } //delete methods deleteContact(id) { return this.http.delete('http://localhost:3000/api/contact'+ id).map(res =&gt; res.json()); } }</pre></div></object> 屬性“結果”在類型“ AppComponent”上不存在 類型 &#39;&#39; 上不存在屬性 屬性“ pname”在類型“ {}”上不存在 類型“{}”上不存在屬性“joiner” Laravel 格式資源集合響應錯誤屬性 [product_id] 在此集合實例上不存在 屬性“位置”在類型“對象”上不存在
 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM