Skip to content

Commit

Permalink
fix(define-props): add missing imports
Browse files Browse the repository at this point in the history
  • Loading branch information
sxzz committed Nov 8, 2022
1 parent 049bd4d commit 078d7ca
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 5 deletions.
5 changes: 5 additions & 0 deletions .changeset/gold-bees-check.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@vue-macros/define-props': patch
---

fix $defineProps retuning type
11 changes: 7 additions & 4 deletions packages/define-props/macros.d.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
import type { ComponentObjectPropsOptions, ExtractPropTypes } from 'vue'
import type { RefValue } from 'vue/macros'

export type RefValueObject<T> = {
[K in keyof T]: RefValue<T[K]>
}

export declare function $defineProps<PropNames extends string = string>(
props: PropNames[]
): Readonly<{
[key in PropNames]?: any
}>
export declare function $defineProps<
PP extends ComponentObjectPropsOptions = ComponentObjectPropsOptions
>(props: PP): Readonly<ExtractPropTypes<PP>>
export declare function $defineProps<TypeProps>(): {
[Key in keyof TypeProps]: RefValue<TypeProps[Key]>
}
>(props: PP): RefValueObject<ExtractPropTypes<PP>>
export declare function $defineProps<TypeProps>(): RefValueObject<TypeProps>
10 changes: 9 additions & 1 deletion packages/define-props/tests/fixtures/basic.vue
Original file line number Diff line number Diff line change
@@ -1,16 +1,24 @@
<script setup lang="ts">
import { $$ } from 'vue/macros'
import { $$, ReactiveVariable } from 'vue/macros'
import { expectTypeOf } from 'expect-type'
import type { Ref } from 'vue'
const { foo, bar } = $defineProps<{
foo: string[]
bar: Ref<number>
}>()
expectTypeOf(foo).toEqualTypeOf<ReactiveVariable<string[]>>()
const fooRef = $$(foo)
const barRef = $$(bar)
expectTypeOf(fooRef).toEqualTypeOf<Ref<string[]>>()
expectTypeOf(barRef).toEqualTypeOf<Ref<Ref<number>>>()
const { baz } = $defineProps({
baz: String,
})
expectTypeOf(baz).toEqualTypeOf<ReactiveVariable<string> | undefined>()
const { qux, quux } = $defineProps(['qux', 'quux'])
</script>

<template>
Expand Down

0 comments on commit 078d7ca

Please sign in to comment.