Skip to content

fix(types): keep type of options#381

Merged
sxzz merged 1 commit intorolldown:mainfrom
posva:types/keep-define-config
Jul 18, 2025
Merged

fix(types): keep type of options#381
sxzz merged 1 commit intorolldown:mainfrom
posva:types/keep-define-config

Conversation

@posva
Copy link
Contributor

@posva posva commented Jul 18, 2025

Description

When using defineConfig({}), the return value cannot be spread because the type includes a function. Since the defineConfig() is just the identity function, it might be better to keep the type as is. Another option is to create an overload function

Linked Issues

Additional context

The current workaround is to use satisfies UserOptions

@netlify
Copy link

netlify bot commented Jul 18, 2025

Deploy Preview for tsdown ready!

Name Link
🔨 Latest commit da1cccd
🔍 Latest deploy log https://app.netlify.com/projects/tsdown/deploys/687a4673d444f3000824f76a
😎 Deploy Preview https://deploy-preview-381--tsdown.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@sxzz
Copy link
Member

sxzz commented Jul 18, 2025

Thanks bro!

@pkg-pr-new
Copy link

pkg-pr-new bot commented Jul 18, 2025

Open in StackBlitz

npm i https://pkg.pr.new/tsdown@381

commit: da1cccd

@sxzz sxzz enabled auto-merge (squash) July 18, 2025 20:14
@sxzz sxzz merged commit 00b5d03 into rolldown:main Jul 18, 2025
13 checks passed
@posva posva deleted the types/keep-define-config branch July 19, 2025 06:22
sxzz added a commit that referenced this pull request Jul 31, 2025
@sxzz
Copy link
Member

sxzz commented Jul 31, 2025

@posva I reverted this PR via 7c32a1d because:

  • Overloading defineConfig (similar to how Vite handles it):
export function defineConfig(options: UserConfig): UserConfig;
export function defineConfig(options: UserConfigFn): UserConfigFn;
export function defineConfig(
  options: UserConfig | UserConfigFn,
): UserConfig | UserConfigFn;
  • Using generics:

    • Provides a more direct error message.
    • However, it doesn't allow jumping to the definition of properties by clicking, and no auto suggestion/completion.
  • Using a union:

    • Makes it impossible to extract specific types.

After evaluating these options, I decided to go with overloading, as Vite does. If you need to achieve type inference, using satisfies is a more appropriate solution.

@posva
Copy link
Contributor Author

posva commented Jul 31, 2025

Of course, I didn’t expect it to break jump to definition. TIL

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants