quasar: For help! Custom quasar perfetch reports an error

Hi~ For help!

package.json "@quasar/app": "^1.6.0", "@quasar/extras": "^1.5.2", "quasar": "^1.9.8" "typescript": "^3.8.3"

quasar.conf.js supportTS: true preFetch: true

Previously there were no errors with the @quasar/typescript plug-in

企业微信截图_15836745205238 企业微信截图_15836745934920

thx!

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Comments: 19 (11 by maintainers)

Commits related to this issue

Most upvoted comments

Let’s keep this open until the related PR is merged 😃

Fix will be available with “quasar” v1.9.16.

I probably also changed something into @quasar/app 🤔 Can you replicate locally the changes I did in the PR?

Problem 2 That’s just standard TypeScript stuff: you cannot augment an already defined method with a conflicting interface. Anyway you pointed me out that the context has not been typed properly, I’ll fix that 😃

Problem 1 Because of how Promise.all is typed, it will always return a promise of an array, while we expect a Promise<void>. There are multiple solutions:

  • you can cast the promise to be the one we need like this
  preFetch(context) {
    return Promise.all([
      new Promise((res, rej) => {
        res();
      })
    ]) as unknown as Promise<void>;
  },
  • you can use async/await to reduce the type to Promise<void> like this
  async preFetch(context) {
    await Promise.all([
      new Promise((res, rej) => {
        res();
      })
    ]);
  },
  • we can change the accepted return type to Promise<{}>, which will accept pretty much everything (even void[] and unknown[])

Source: https://stackoverflow.com/questions/43597503/type-void-array-not-assignable-to-type-void