types: improve readability of built-in type
Description
We could write this in code, but the types would be unwrapped:
const date = ref(new Date())
We can declare types that should avoid reference unwrapping by writing:
declare module '@vue/reactivity' {
Export interface RefUnwrapBailTypes {
Date: Date;
}
}
But Date is a commonly used built-in type, would it be better if we support it directly?
Before
const date: Ref<{
toString: () => string;
toDateString: () => string;
toTimeString: () => string;
toLocaleString: {
(): string;
(locales?: string | string[] | undefined, options?: Intl.DateTimeFormatOptions | undefined): string;
(locales?: Intl.LocalesArgument, options?: Intl.DateTimeFormatOptions | undefined): string;
};
... 39 more ...;
[Symbol.toPrimitive]: {
...;
};
}>
After
const date: Ref<Date>
Size Report
Bundles
| File | Size | Gzip | Brotli |
|---|---|---|---|
| runtime-dom.global.prod.js | 86.9 kB | 33.1 kB | 29.9 kB |
| vue.global.prod.js | 133 kB | 49.9 kB | 44.7 kB |
Usages
| Name | Size | Gzip | Brotli |
|---|---|---|---|
| createApp | 48.3 kB | 19 kB | 17.3 kB |
| createSSRApp | 51.5 kB | 20.3 kB | 18.5 kB |
| defineCustomElement | 50.7 kB | 19.8 kB | 18.1 kB |
| overall | 61.7 kB | 23.9 kB | 21.7 kB |
I deleted BaseTypes because its definition overlaps with Builtin.
CodSpeed Performance Report
Merging #9129 will improve performances by 63.31%
Comparing Mini-ghost:type/support-date-type (57dc127) with main (9d1ca32)
Summary
âš¡ 1 improvements
✅ 52 untouched benchmarks
Benchmarks breakdown
| Benchmark | main |
Mini-ghost:type/support-date-type |
Change | |
|---|---|---|---|---|
| âš¡ | reduce *readonly* array, 10 elements |
1.8 ms | 1.1 ms | +63.31% |
I think you misunderstood what I meant - BuiltIn should include Primitive. This PR shouldn't alter how Builtin works.
That said my last requested change seems unnecessary, since UnwrapRefSimple is only checking for object / collection types so your previous implementation was actually ok and we should revert to that one. Sorry for the confusion!
Understood! I will revert back to the previous commit.