Skip to content

Commit

Permalink
fix: handle optional prop with default
Browse files Browse the repository at this point in the history
  • Loading branch information
jh-leong committed Oct 22, 2024
1 parent 15c6f92 commit 4a3bc4e
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
5 changes: 5 additions & 0 deletions packages-private/dts-test/setupHelpers.test-d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -456,6 +456,11 @@ describe('defineModel', () => {
defineModel<() => number>({
default: () => '',
})
// @ts-expect-error
// optional prop with default
defineModel<{ id?: number }>({
default: () => ({ foo: 'bar' }),
})
}

// @ts-expect-error unknown props option
Expand Down
4 changes: 2 additions & 2 deletions packages/runtime-core/src/apiSetupHelpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ export type DefineModelOptions<T = any, G = T, S = T> = {
* ```
*/
export function defineModel<T, M extends PropertyKey = string, G = T, S = T>(
options: ({ default: any } | { required: true }) &
options: ({ default: NonNullable<unknown> } | { required: true }) &
PropOptions<T> &
DefineModelOptions<T, G, S>,
): ModelRef<T, M, G, S>
Expand All @@ -296,7 +296,7 @@ export function defineModel<T, M extends PropertyKey = string, G = T, S = T>(

export function defineModel<T, M extends PropertyKey = string, G = T, S = T>(
name: string,
options: ({ default: any } | { required: true }) &
options: ({ default: NonNullable<unknown> } | { required: true }) &
PropOptions<T> &
DefineModelOptions<T, G, S>,
): ModelRef<T, M, G, S>
Expand Down

0 comments on commit 4a3bc4e

Please sign in to comment.