Skip to content

Commit

Permalink
fix(define-props-refs): nested props w/ withDefaults
Browse files Browse the repository at this point in the history
closes #348
  • Loading branch information
sxzz committed Apr 29, 2023
1 parent 3bf2d6a commit 50f8fe5
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 4 deletions.
5 changes: 5 additions & 0 deletions .changeset/sharp-colts-sparkle.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@vue-macros/define-props-refs': patch
---

fix nested props w/ withDefaults in definePropsRefs
9 changes: 5 additions & 4 deletions packages/define-props-refs/macros.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@ export declare type PropsWithDefaults<Base, Defaults> = Base & {
: never
}

export declare function withDefaults<
Props,
Defaults extends InferDefaults<Props>
>(props: Props, defaults: Defaults): PropsWithDefaults<Props, Defaults>

export declare function withDefaults<
PropsWithRefs extends PropRefs<Record<string, any>>,
Defaults extends InferDefaults<Props>,
Expand All @@ -45,10 +50,6 @@ export declare function withDefaults<
: PropsWithRefs[K]
}
>(props: PropsWithRefs, defaults: Defaults): PropRefs<Props>
export declare function withDefaults<
Props,
Defaults extends InferDefaults<Props>
>(props: Props, defaults: Defaults): PropsWithDefaults<Props, Defaults>

export declare function definePropsRefs<PropNames extends string = string>(
props: PropNames[]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,30 @@ expectTypeOf(bar).toEqualTypeOf<ComputedRef<readonly number[]>>()
</script>
"
`;
exports[`fixtures > ./fixtures/with-defaults-define-props.vue 1`] = `
"<script setup lang=\\"ts\\">
const __MACROS_props = withDefaults(defineProps<Props>(), {
modelValue: () => ({
signatureAppearance: 'none',
}),
})
import { toRefs as __MACROS_toRefs } from \\"vue\\";
import { expectTypeOf } from 'expect-type'
interface Props {
modelValue?: {
signatureAppearance: 'none'
}
}
// definePropsRefs
const props = __MACROS_toRefs(__MACROS_props)
expectTypeOf(props.modelValue).toEqualTypeOf<{
signatureAppearance: 'none'
}>()
</script>
"
`;
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<script setup lang="ts">
import { expectTypeOf } from 'expect-type'
interface Props {
modelValue?: {
signatureAppearance: 'none'
}
}
// definePropsRefs
const props = withDefaults(defineProps<Props>(), {
modelValue: () => ({
signatureAppearance: 'none',
}),
})
expectTypeOf(props.modelValue).toEqualTypeOf<{
signatureAppearance: 'none'
}>()
</script>

0 comments on commit 50f8fe5

Please sign in to comment.