Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 5 commits into from
Nov 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion packages/dts-test/setupHelpers.test-d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ import {
defineSlots,
VNode,
Ref,
defineModel
defineModel,
toRefs
} from 'vue'
import { describe, expectType } from './utils'
import { defineComponent } from 'vue'
Expand All @@ -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)
Expand Down Expand Up @@ -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)
})
5 changes: 3 additions & 2 deletions packages/runtime-core/src/apiSetupHelpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ import {
isFunction,
Prettify,
UnionToIntersection,
extend
extend,
LooseRequired
} from '@vue/shared'
import {
getCurrentInstance,
Expand Down Expand Up @@ -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
Expand Down