Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(gatsby): Make plugins in PluginOptions type optional #36351

Merged
merged 1 commit into from
Aug 10, 2022

Conversation

LekoArts
Copy link
Contributor

Description

So I've ran into this while I defined a interface CustomPluginOptions extends PluginOptions in a plugin. I extend the PluginOptions from gatsby here so that I can use it in the gatsby-config and in the gatsby-node APIs.

But with plugins being required TS complained that my plugin didn't define plugins.

import type { GatsbyConfig, PluginRef } from "gatsby"
import type { CustomPluginOptions } from "plugin"

const config: GatsbyConfig = {
  plugins: [
    {
      resolve: `plugin`,
      options: {
        api_key: process.env.api_key,
        plugins: [], // This here is necessary to add at the moment
      } as CustomPluginOptions,
    },
  ] as PluginRef[],
}

export default config

I know, we set this by default, but for using this type in 3rd party packages it's annoying

@LekoArts LekoArts added the topic: TypeScript Issues and PRs related to TS in general, public typings or gatsby-plugin-typescript label Aug 10, 2022
@gatsbot gatsbot bot added the status: triage needed Issue or pull request that need to be triaged and assigned to a reviewer label Aug 10, 2022
@LekoArts LekoArts removed the status: triage needed Issue or pull request that need to be triaged and assigned to a reviewer label Aug 10, 2022
@marvinjude marvinjude merged commit a2fa5a2 into master Aug 10, 2022
@marvinjude marvinjude deleted the chore-fix-plugin-typing branch August 10, 2022 12:20
@pieh
Copy link
Contributor

pieh commented Aug 10, 2022

I think you want to extend IPluginRefOptions, not PluginOptions for gatsby-config inputs at least. First one are types for the input (with plugins being optional), PluginOptions will be values passed to our APIs and plugins will always be an array there

marvinjude added a commit that referenced this pull request Aug 10, 2022
LekoArts added a commit that referenced this pull request Aug 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
topic: TypeScript Issues and PRs related to TS in general, public typings or gatsby-plugin-typescript
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants