]> git.ipfire.org Git - thirdparty/vuejs/core.git/commitdiff
fix(types): remove optional properties from defineProps return type (#6421)
authorCarlos Rodrigues <carlos@hypermob.co.uk>
Thu, 9 Nov 2023 06:52:28 +0000 (06:52 +0000)
committerGitHub <noreply@github.com>
Thu, 9 Nov 2023 06:52:28 +0000 (14:52 +0800)
close #6420

packages/dts-test/setupHelpers.test-d.ts
packages/runtime-core/src/apiSetupHelpers.ts

index feb4085dea064aa0ab6bd1d9b3c58d270e21473d..838e376da2dee494958e5fa34f2f117d2d43e7d3 100644 (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)
+})
index 93200667081b1925af0fb7fe1246f3b38e5835f5..cff0c6511e289606307138d1b3fc29e47d382610 100644 (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