2021年1月29日星期五

Error: Type 'XX' is not a valid async function return type in ES5/ES3 because it does not refer to a Promise-compatible constructor value

I don't understand why handle3 is getting this error.

All the three methods is the same with different notation, isn't it? Is this a bug of ts?

type UseCaseResponse = Promise<any>      class Foo {      async handle(): Promise<any> {          return await Promise.resolve('x')      }        handle2(): UseCaseResponse {          return Promise.resolve('x')      }        async handle3(): UseCaseResponse {          return await Promise.resolve('x')      }  }  

tsconfig.json

{      "compilerOptions": {          "outDir": "./built/",          "sourceMap": true,          "strict": true,          "strictPropertyInitialization": false,          "noImplicitReturns": true,          "noImplicitAny": true,          "experimentalDecorators": true,          "emitDecoratorMetadata": true,          "moduleResolution": "node",          "target": "ES5",          "downlevelIteration": true,          "esModuleInterop": true,          "resolveJsonModule": true,          "allowJs": true,          "baseUrl": "./resources/js",          "types" : [              "jquery"          ],          "paths": {              "@/*": [                  "*"              ]          },          "lib": [              "es2016",              "dom"          ]      },      "include": [          "resources/js/**/*"      ],      "plugins": [          { "name": "typescript-tslint-plugin" }      ]  }  
https://stackoverflow.com/questions/65963637/error-type-xx-is-not-a-valid-async-function-return-type-in-es5-es3-because-it January 30, 2021 at 09:01AM

没有评论:

发表评论