fix(types): remove optional properties from defineProps return type (#6421)

close #6420
This commit is contained in:
Carlos Rodrigues 2023-11-09 06:52:28 +00:00 committed by GitHub
parent 9d0eba916f
commit 94c049d930
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 3 deletions

View File

@ -8,7 +8,8 @@ import {
defineSlots,
VNode,
Ref,
defineModel
defineModel,
toRefs
} from 'vue'
import { describe, expectType } from './utils'
import { defineComponent } from 'vue'
@ -20,6 +21,7 @@ describe('defineProps w/ type declaration', () => {
foo: string
bool?: boolean
boolAndUndefined: boolean | undefined
file?: File | File[]
}>()
// explicitly declared type should be refined
expectType<string>(props.foo)
@ -328,3 +330,11 @@ describe('useSlots', () => {
const slots = useSlots()
expectType<Slots>(slots)
})
// #6420
describe('toRefs w/ type declaration', () => {
const props = defineProps<{
file?: File | File[]
}>()
expectType<Ref<File | File[] | undefined>>(toRefs(props).file)
})

View File

@ -4,7 +4,8 @@ import {
isFunction,
Prettify,
UnionToIntersection,
extend
extend,
LooseRequired
} from '@vue/shared'
import {
getCurrentInstance,
@ -82,7 +83,7 @@ export function defineProps<
>(props: PP): Prettify<Readonly<ExtractPropTypes<PP>>>
// overload 3: typed-based declaration
export function defineProps<TypeProps>(): DefineProps<
TypeProps,
LooseRequired<TypeProps>,
BooleanKey<TypeProps>
>
// implementation