vuepress / vuepress-community

:bulb: Community supported ecosystem for VuePress
https://vuepress-community.netlify.app
MIT License
81 stars 62 forks source link

fix(types): allow async function for `additionalPages` #30

Closed lojgmyrht closed 4 years ago

lojgmyrht commented 4 years ago

Summary

Which package does this PR involve? (check one)

What kind of change does this PR introduce? (check at least one)

Does this PR introduce a breaking change? (check one)

If yes, please describe the impact and migration path for existing applications:

The PR fulfills these requirements:

Other information: According to the docs, the correct type for the additionalPages property of a plugin's options is Array | AsyncFunction.

Currently, code like this:

const GhostPlugin: Plugin<MyPluginOptions> = (options, context) => ({
  async additionalPages(): Promise<Partial<PageOptions>[]> {
    const pages: Partial<PageOptions>[] = getMyPages()
    return pages
  }
})

produces this error when compiling the plugin.

Type '() => Promise<Partial<PageOptions>[]>' is not assignable to type 'Partial<PageOptions>[] | Promise<Partial<PageOptions>[]> | undefined'

Passing a Promise instead of an async function produces

warning: Invalid value for "option" additionalPages: expected a Function or Array but got Promise.

when using the plugin with VuePress.

This PR enables passing an async function for additionalPages.

meteorlxy commented 4 years ago

Nice catch! Thanks a lot ❤️