Skip to content

Commit 19880a7

Browse files
committed
fix(types): include undefined type for optional prop definition
1 parent f331773 commit 19880a7

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

src/props.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ export function prop<T>(options: PropOptionsWithDefault<T>): WithDefault<T>
4848
export function prop<T>(options: PropOptionsWithRequired<T>): T
4949

5050
// Others
51-
export function prop<T>(options: Prop<T>): T
51+
export function prop<T>(options: Prop<T>): T | undefined
5252

5353
// Actual implementation
5454
export function prop(options: Prop<unknown>): unknown {

test-dts/props.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { PropType } from 'vue'
12
import { prop, Vue } from '../src'
23

34
describe('props', () => {
@@ -18,6 +19,12 @@ describe('props', () => {
1819
}),
1920
})
2021

22+
optional = prop(Object as PropType<Person>)
23+
required = prop({
24+
type: String,
25+
required: true,
26+
})
27+
2128
// @ts-expect-error
2229
invalidDefault: string = prop({ default: 'default' })
2330
}
@@ -30,10 +37,14 @@ describe('props', () => {
3037
equals<typeof vm.bar, number | undefined>(true)
3138
equals<typeof vm.baz, boolean>(true)
3239
equals<typeof vm.qux, Person>(true)
40+
equals<typeof vm.optional, Person | undefined>(true)
41+
equals<typeof vm.required, string>(true)
3342
equals<typeof vm.$props.foo, string>(true)
3443
equals<typeof vm.$props.bar, number | undefined>(true)
3544
equals<typeof vm.$props.baz, boolean | undefined>(true)
3645
equals<typeof vm.$props.qux, Person | undefined>(true)
46+
equals<typeof vm.$props.optional, Person | undefined>(true)
47+
equals<typeof vm.$props.required, string>(true)
3748

3849
// @ts-expect-error
3950
vm.notExists

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy