Skip to content

Fixed type safety in props for Ref values. #469

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion packages/vue-final-modal/src/Component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@
* Copy from https://github.com/vuejs/language-tools/tree/master/packages/component-type-helpers
*/

import { MaybeRefProps } from '~/utils';

// export type ComponentType<T> =
// T extends new () => {} ? 1 :
// T extends (...args: any) => any ? 2 :
// 0

export type ComponentProps<T> =
T extends new () => { $props: infer P } ? NonNullable<P> :
T extends new () => { $props: infer P } ? MaybeRefProps<NonNullable<P>> :
T extends (props: infer P, ...args: any) => any ? P :
{}

Expand Down
6 changes: 6 additions & 0 deletions packages/vue-final-modal/src/utils.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import type { Ref } from 'vue'

export const once
= (fn: null | ((...args: any[]) => void)) =>
(...args: any[]) => {
Expand Down Expand Up @@ -39,3 +41,7 @@ type Entries<T> = { [K in keyof T]: [K, T[K]] }[keyof T][]
export function objectEntries<T extends Record<any, any>>(object: T): Entries<T> {
return Object.entries(object) as any
}

export type MaybeRefProps<P> = {
[K in keyof P]: Ref<P[K]> | P[K];
}