Skip to content

Commit 94c049d

Browse files
authored
fix(types): remove optional properties from defineProps return type (#6421)
close #6420
1 parent 9d0eba9 commit 94c049d

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

packages/dts-test/setupHelpers.test-d.ts

+11-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ import {
88
defineSlots,
99
VNode,
1010
Ref,
11-
defineModel
11+
defineModel,
12+
toRefs
1213
} from 'vue'
1314
import { describe, expectType } from './utils'
1415
import { defineComponent } from 'vue'
@@ -20,6 +21,7 @@ describe('defineProps w/ type declaration', () => {
2021
foo: string
2122
bool?: boolean
2223
boolAndUndefined: boolean | undefined
24+
file?: File | File[]
2325
}>()
2426
// explicitly declared type should be refined
2527
expectType<string>(props.foo)
@@ -328,3 +330,11 @@ describe('useSlots', () => {
328330
const slots = useSlots()
329331
expectType<Slots>(slots)
330332
})
333+
334+
// #6420
335+
describe('toRefs w/ type declaration', () => {
336+
const props = defineProps<{
337+
file?: File | File[]
338+
}>()
339+
expectType<Ref<File | File[] | undefined>>(toRefs(props).file)
340+
})

packages/runtime-core/src/apiSetupHelpers.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ import {
44
isFunction,
55
Prettify,
66
UnionToIntersection,
7-
extend
7+
extend,
8+
LooseRequired
89
} from '@vue/shared'
910
import {
1011
getCurrentInstance,
@@ -82,7 +83,7 @@ export function defineProps<
8283
>(props: PP): Prettify<Readonly<ExtractPropTypes<PP>>>
8384
// overload 3: typed-based declaration
8485
export function defineProps<TypeProps>(): DefineProps<
85-
TypeProps,
86+
LooseRequired<TypeProps>,
8687
BooleanKey<TypeProps>
8788
>
8889
// implementation

0 commit comments

Comments
 (0)