Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/typescript/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angular2/Typescript编译错误:属性';车身';不存在于类型';答复';_Typescript - Fatal编程技术网

Angular2/Typescript编译错误:属性';车身';不存在于类型';答复';

Angular2/Typescript编译错误:属性';车身';不存在于类型';答复';,typescript,Typescript,不知道该怎么处理 我尝试定义类型为的接口 Error TS2339: Property 'body' does not exist on type 'Response'. 接口结果数据{ 正文:字符串 } 然后将其用作: interface ResultData<T> { body: string } this.getVerificationCode('1111111'){ 让url=`${remote}/auth/phoneNumber/${phoneNumber}`;

不知道该怎么处理

我尝试定义类型为的接口

Error TS2339: Property 'body' does not exist on type 'Response'.
接口结果数据{
正文:字符串
}
然后将其用作:

interface ResultData<T> {
  body: string
}
this.getVerificationCode('1111111'){
让url=`${remote}/auth/phoneNumber/${phoneNumber}`;
返回此。\u http.get(url)
.toPromise()
。然后((结果:ResultData)=>{
console.log(result.body);试试看

getVerificationCode(电话号码){
让url=`${remote}/auth/phoneNumber/${phoneNumber}`;
返回此。\u http.get(url)
.toPromise()
.然后((结果:对象)=>{
console.log(result.body);试试看

getVerificationCode(电话号码){
让url=`${remote}/auth/phoneNumber/${phoneNumber}`;
返回此。\u http.get(url)
.toPromise()
.然后((结果:对象)=>{
console.log(result.body);
interface ResultData<T> {
  body: string
}
this.getVerificationCode('1111111') {
    let url = `${remote}/auth/phoneNumber/${phoneNumber}`;
     return this._http.get(url)
           .toPromise()
           .then( (result: ResultData<any> )=> {
                   console.log(result.body);  <--- ERROR
                });
Error TS2345: Argument of type '(result: ResultData<any>) => void' is not assignable to parameter of type '(value: Response) => void | PromiseLike<void>'.
  Types of parameters 'result' and 'value' are incompatible.
    Type 'Response' is not assignable to type 'ResultData<any>'.
      Property 'body' is missing in type 'Response'.
getVerificationCode(phoneNumber) {
    let url = `${remote}/auth/phoneNumber/${phoneNumber}`;
    return this._http.get(url)
        .toPromise()
        .then((result: Object) => {
           console.log(result.body);  <--- ERROR
        });
  }