-
-
Notifications
You must be signed in to change notification settings - Fork 8.4k
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
types(runtime-dom): type for class property #8012
types(runtime-dom): type for class property #8012
Conversation
Can you also add type-related test cases here? https://github.com/vuejs/core/blob/main/packages/dts-test/tsx.test-d.tsx |
Sure. Done ✅ |
packages/runtime-dom/src/jsx.ts
Outdated
export type ClassValue = | ||
| undefined | ||
| string | ||
| Record<string, boolean> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Technically the Record value can be any truthy/falsy value.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If I understand correctly, you want me to extend the possible accepted values in the Record
type to also accept truthy/falsy types for maximum backward compatibility with older versions of Vue?
For example:
type Truthy = true | string | number | {} | any[];
type Falsy = false | 0 | -0 | 0n | '' | null | undefined | NaN;
and result record type will be:
Record<string, Truthy | Falsy>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not really, what I mean is the value should technically allow any
since any value in JS is either truthy or falsy.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah. I understand what you mean.
So, then there are two possible solutions:
- Try to formalize it something like this:
type Falsy = false | 0 | -0 | 0n | '' | null | undefined | typeof NaN;
type Truthy<T> = T extends Falsy ? never : T;
export type ClassValue =
| undefined
| string
| Record<string, Falsy | Truthy<unknown>>
| Array<ClassValue>
- Just set the
unknown
type (orany
at the very least):
export type ClassValue =
| undefined
| string
| Record<string, unknown>
| Array<ClassValue>
I think the second option will be easier and more priority, right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@yyx990803 I'm sorry to bother you, but could you please rerewiew the changes? It's been two months since the last activity here. Thanks!
Someone is attempting to deploy a commit to the vuejs Team on Vercel. A member of the Team first needs to authorize it. |
Co-authored-by: 三咲智子 Kevin Deng <sxzz@sxzz.moe>
Size ReportBundles
Usages
|
The latest updates on your projects. Learn more about Vercel for Git ↗︎ 1 Ignored Deployment
|
This PR breaks vuetify: |
reverts #8012 due to breakage in downstream types
What should I do now? 🙃 |
I don't think we can land this change, honestly. Vuetify is just one of the examples of how downstream projects can be affected - there could be many more cases (e.g. in private production projects) that use similar types. We can't just go out there and help them fix it. In a way, |
Sometimes it's so sad that
HTMLAttributes['class']
type is anany
.Developers have to "reinvent the wheel" or blindly hope that it will be added someday.
This is the day :)
I think it would be useful to add normal type and remove
any
.I also added new tests for
normalizeClass
, some of them related to #7869.