简体   繁体   English

类型诺言中不存在属性映射<void>

[英]property map does not exist on type promise<void>

In my angular 6 project am getting property map does not exist on type promise error even I included 在我的angular 6项目中,即使我包含了,但类型承诺错误也不存在属性映射

import 'rxjs/add/operator/map';
import 'rxjs/add/operator/catch';
import 'rxjs/add/operator/toPromise';

Following is my code 以下是我的代码

 submit(): Promise<any> {
        return http.post('api/SubmitEmployee', JSON.stringify(this.formData))
            .map((response: Response) => <any>response.json())
            .toPromise()
            .catch(this.handlePromiseError)
    }

    handlePromiseError(error: Response) {
        console.log(error)
    }

After some google I found solution like below but that is also not working 经过一些谷歌,我发现下面的解决方案,但也无法正常工作

import { map } from 'rxjs/operators';  

pipe(map((response: Response) => response.json()))

After including this it shows error property type does not exist on type promise Following is my custom post method 包含此内容后,它表明诺言类型上不存在错误属性类型,这是我的自定义post方法

post(url: string, content: any, resolve: ResolveFunction = null, reject: RejectFunction = null) {
    this.clearCache();
    const retryFunc = _ => this.post(url, content, resolve, reject);
    return fetch(appSettings.baseApiUri + url, {
      method: 'POST',
      headers: this.getCustomHeader(),
      body: content
    })
      .then(result => {
        this.handleResponse(url, result, retryFunc, resolve, reject);
      })
      .catch(error =>
        this.debounce(_ => this.handleError(url, error, retryFunc).catch(_ => reject(error)), this.debounceTimeout)
      );
  }

使用from来包装http.post,例如from(http.post()。then()),它返回一个可观察的对象,以便您可以通过管道传输流

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 类型 &#39;Promise&#39; 上不存在属性 &#39;finally&#39;<void> &#39; - Property 'finally' does not exist on type 'Promise<void>' 属性“地图”在类型“可观察”上不存在 <Response> ”。 使用Promise的角度 - Property 'map' does not exist on type 'Observable<Response>'. angular for using Promise 然后保证Angular 7-类型&#39;void&#39;不存在&#39;then&#39; - then promise Angular 7 - 'then' does not exist on type 'void' 类型为forEach的属性在类型void上不存在 - property of type forEach does not exist on type void 错误 TS2339:属性 &#39;finally&#39; 在类型 &#39;Promise 上不存在<void> &#39; - error TS2339: Property 'finally' does not exist on type 'Promise<void>' &#39;PromiseLike&#39;类型中不存在属性&#39;catch&#39; <void> “ - Property 'catch' does not exist on type 'PromiseLike<void>' 类型 void 上不存在 Angular 属性订阅 - Angular Property subscribe does not exist on type void Angularfire2属性“ then”在“ void”类型上不存在 - Angularfire2 Property 'then' does not exist on type 'void' 然后,属性在void类型上不存在,打字稿错误 - property then does not exist on type void , A typescript error “void”类型上不存在属性“管道”Angular 6 - Property 'pipe' does not exist on type 'void' Angular 6
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM