skip to Main Content

This is my class.

export MyClass {
    
    private readonly ServiceEndpoint: string = 
    "/xxx/xxx.DMS.UI.Root/Services/ConfigurationAPI.svc/";
    
    
    public async GetAllCompanies(): Promise<CompanyDto[]> {
    return fetchAsync(
        `${this.ServiceEndpoint}Company`,
        'GET'
        )
      .then(value => value.GetAllCompaniesResult);
  }

}

Presently, this method returns a Promise <CompanyDto[]>. How do I rewrite it so that it returns only the result CompanyDto[]?

2

Answers


  1. I think you are missing await keyword here. Can you please try using await.

    export MyClass {
    
    private readonly ServiceEndpoint: string = 
    "/xxx/xxx.DMS.UI.Root/Services/ConfigurationAPI.svc/";
    
    
    public async GetAllCompanies(): Promise<CompanyDto[]> {
       let result = await fetchAsync(
        `${this.ServiceEndpoint}Company`,
        'GET'
        )
      .then(value => value.GetAllCompaniesResult);
      return result; 
    

    }

    }

    Login or Signup to reply.
  2. Just use await. Make sure your types are correctly inferred.

    export MyClass {
        
        private readonly ServiceEndpoint: string = 
        "/xxx/xxx.DMS.UI.Root/Services/ConfigurationAPI.svc/";
        
        
        public async GetAllCompanies(): CompanyDto[] {
          const result = await fetchAsync(
            `${this.ServiceEndpoint}Company`,
            'GET'
            );
          
          return result.GetAllCompaniesResult;
        }
    
    }
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search