typescript - TS2345: Argument of type 'Promise<ReadonlyArray<Object>>' is not assignable to parameter of type 'T | PromiseLike<T> | undefined' -


what trying return the readonlyarray<> in promise can return original method called 'dispatchtothisprocess', reason why doing abstract state update can change update multiple processes in future. bellow code:

private dispatchtothisprocess<t extends object>(action: action): promise<t> {     return this.updatestate(action.name, action)   }   // called dispatchtothisprocess   private updatestate<t extends object> (name: string, args: any): promise<t> {     return new promise<t>((resolve, reject) => {       console.log('in updatestate, replaced send<t>(...) method')       switch (name) {         case 'add-repositories': {           const addedrepos: readonlyarray<repository> = new array<repository>()           (const path of args) {             const addedrepo: = promise             .resolve(this.repositoriesstore.addrepository(path))             .then(result => addedrepo)             addedrepos.join(addedrepo)           }           const returned = promise.resolve(addedrepos)           resolve(returned)           break;         }         default: {           reject()           break;         }       }     })   } 

here error get:

 error ts2345: argument of type 'promise<readonlyarray<repository>>' not assignable parameter of type 't | promiselike<t> | undefined'.   type 'promise<readonlyarray<repository>>' not assignable type 'promiselike<t>'.     types of property 'then' incompatible.       type '<tresult1 = readonlyarray<repository>, tresult2 = never>(onfulfilled?: ((value: readonlyarray<rep...' not assignable type '<tresult1 = t, tresult2 = never>(onfulfilled?: ((value: t) => tresult1 | promiselike<tresult1>) |...'.         types of parameters 'onfulfilled' , 'onfulfilled' incompatible.           types of parameters 'value' , 'value' incompatible.             type 'readonlyarray<repository>' not assignable type 't'. 

i looked up, people add t extends object did not in case, not know go here. i'm using typescript 2.4.0.

updatestate returning single t. want return readonlyarray of them.

  private updatestate<t extends object> (name: string, args: any): promise<readonlyarray<t>> {     return new promise<readonlyarray<t>>((resolve, reject) => { 

Comments

Popular posts from this blog

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

python Tkinter Capturing keyboard events save as one single string -

sql server - Why does Linq-to-SQL add unnecessary COUNT()? -