Skip to content

Conversation

DamianGlowala
Copy link
Member

@DamianGlowala DamianGlowala commented Jun 11, 2024

🔗 Linked issue

📚 Description

Currently, defining the defaults for options in defineNuxtModule does not impact the type of resolvedOptions param within the setup function. Their types are disconnected, which this PR aims to address.

As of today, TypeScript does not support partial inference of generic type params. Due to this fact, I'd like to suggest adding an extra function call (named with), which can handle merging inferred defaults with the module options generic type param and therefore improve both the type safety and DX:

type ModuleOptions = {
  option1: string
  option2: number
}

defineNuxtModule<ModuleOptions>().with({
  defaults: {
    option1: 'foo'
  },
  setup: (resolvedOptions) => {}
         // ^? { option1: string, option2?: number | undefined }
})

Copy link

Review PR in StackBlitz Codeflow Run & review this pull request in StackBlitz Codeflow.

@DamianGlowala DamianGlowala self-assigned this Jun 11, 2024
@DamianGlowala DamianGlowala requested a review from danielroe June 12, 2024 18:23
Copy link
Member

@danielroe danielroe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you! ❤️

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants