How do you properly return multiple values from a promise?

后端 未结 9 1402
慢半拍i
慢半拍i 2020-12-04 14:14

I\'ve recently run into a certain situation a couple of times, which I didn\'t know how to solve properly. Assume the following code:

somethingAsync()
  .the         


        
9条回答
  •  难免孤独
    2020-12-04 14:35

    Simply return a tuple:

    async add(dto: TDto): Promise {
    console.log(`${this.storeName}.add(${dto})`);
    return firebase.firestore().collection(this.dtoName)
      .withConverter(this.converter)
      .add(dto)
      .then(d => [d.update(this.id, d.id), d.id] as [any, string])
      .then(x => this.get(x[1]));
    

    }

提交回复
热议问题