2
を活字体は、プロパティ名をタイプ上に存在しない文句PostResponse []この行のPOSTDATA()メソッドで
return this.http.post<PostResponse[]>(`${this.ROOT_URL}/users`, data).map(res => res.name);
それはPostResponse []型に存在しないプロパティ名を訴えます。ここで
は、サービス内の完全なコードで、
import { Injectable } from '@angular/core';
import { HttpClient, HttpParams, HttpHeaders } from '@angular/common/http';
import { Observable } from 'rxjs/Observable';
import { ItemsResponse } from './data.interface';
import 'rxjs/add/operator/map';
interface PostResponse {
data: [
{
name: string;
job: string;
}
];
}
@Injectable()
export class RepositoryService {
readonly ROOT_URL = 'https://reqres.in/api';
constructor (private http: HttpClient) {
console.log('idea repository service instance');
}
postData(): Observable<PostResponse> {
const data = [ {
name: 'Morpheus',
job: 'Developer'
} ];
return this.http.post<PostResponse[]>(`${this.ROOT_URL}/users`, data).map(res => res[0].name);
}
}
は、誰かが適切に型キャストとするときPostResponse []とPostResponseを使用する方法を教えてできますか?
私たちは[チャットでこのディスカッションを続行しましょう](http:// chat .stackoverflow.com/rooms/157627/discussion-between-llai-and-karty)。 – LLai