提交 19880a72 编写于 作者: K ktsn

fix(types): include undefined type for optional prop definition

上级 f331773f
......@@ -48,7 +48,7 @@ export function prop<T>(options: PropOptionsWithDefault<T>): WithDefault<T>
export function prop<T>(options: PropOptionsWithRequired<T>): T
// Others
export function prop<T>(options: Prop<T>): T
export function prop<T>(options: Prop<T>): T | undefined
// Actual implementation
export function prop(options: Prop<unknown>): unknown {
......
import { PropType } from 'vue'
import { prop, Vue } from '../src'
describe('props', () => {
......@@ -18,6 +19,12 @@ describe('props', () => {
}),
})
optional = prop(Object as PropType<Person>)
required = prop({
type: String,
required: true,
})
// @ts-expect-error
invalidDefault: string = prop({ default: 'default' })
}
......@@ -30,10 +37,14 @@ describe('props', () => {
equals<typeof vm.bar, number | undefined>(true)
equals<typeof vm.baz, boolean>(true)
equals<typeof vm.qux, Person>(true)
equals<typeof vm.optional, Person | undefined>(true)
equals<typeof vm.required, string>(true)
equals<typeof vm.$props.foo, string>(true)
equals<typeof vm.$props.bar, number | undefined>(true)
equals<typeof vm.$props.baz, boolean | undefined>(true)
equals<typeof vm.$props.qux, Person | undefined>(true)
equals<typeof vm.$props.optional, Person | undefined>(true)
equals<typeof vm.$props.required, string>(true)
// @ts-expect-error
vm.notExists
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册