core icon indicating copy to clipboard operation
core copied to clipboard

types: improve readability of built-in type

Open Mini-ghost opened this issue 2 years ago • 5 comments

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>

Mini-ghost avatar Sep 04 '23 18:09 Mini-ghost