-
-
Notifications
You must be signed in to change notification settings - Fork 225
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
fix: type narrowing for builder props #1015
fix: type narrowing for builder props #1015
Conversation
🦋 Changeset detectedLatest commit: 609671a The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
…/anatolzak/melt-ui into fix/type-narrowing-builder-props
I wonder if we can be smarter with this. Using something like this: https://xebia.com/blog/typescript-5-0-and-the-new-const-modifier-on-type-parameters/ |
@TGlide that would definitely be preferable! I actually tried adding the const modifier before using |
I tried using the const modifier and was almost able to do it but it seems like TS has a weird bug that breaks its behavior when used in more complex situations. The objective is for the props returned from builders to be interpreted as const by using the const modifier with generics to avoid adding I created a mini version of the Without declaring the store values parameter, the object is interpreted as const. ✅If we declare the store values parameter (most commonly used pattern), the object is no longer interpreted as const. 🚫If we add an explicit type for the store values parameter, the object is interpreted as const. Note that TS already knew the type of the parameter without needing to explicitly define it. But for some reason adding the explicit type, makes the object be interpreted as const. 🚫 |
@TGlide Unless I am missing something with the const modifier, it seems like it's a little broken and so maybe we should just use |
added
as const
to every object returned from...Before
After