]> git.ipfire.org Git - thirdparty/vuejs/core.git/commitdiff
types(runtime-core): make `this` void in prop validators and prop default factories...
authorAurelius333 <22969541+Aurelius333@users.noreply.github.com>
Tue, 18 Aug 2020 15:25:55 +0000 (11:25 -0400)
committerGitHub <noreply@github.com>
Tue, 18 Aug 2020 15:25:55 +0000 (11:25 -0400)
packages/runtime-core/src/componentOptions.ts
test-dts/defineComponent.test-d.tsx

index 816a49c608ebbbb16240117f46a42e2169424611..9c9e2c13a736d8a6b00e582e5a87c8e9a8378662 100644 (file)
@@ -217,7 +217,7 @@ export type ComponentOptionsWithObjectProps<
   EE extends string = string,
   Props = Readonly<ExtractPropTypes<PropsOptions>>
 > = ComponentOptionsBase<Props, RawBindings, D, C, M, Mixin, Extends, E, EE> & {
-  props: PropsOptions
+  props: PropsOptions & ThisType<void>
 } & ThisType<
     CreateComponentPublicInstance<
       Props,
index 1dbb192914508ff27f494c16639beb82a5d4b8c6..41b26f266ab28f1ee101fa3bac83d247e7955802 100644 (file)
@@ -210,6 +210,27 @@ describe('with object props', () => {
   )
   // @ts-expect-error
   expectError(<MyComponent b="foo" dd={{ n: 'string' }} ddd={['foo']} />)
+
+  // `this` should be void inside of prop validators and prop default factories
+  defineComponent({
+    props: {
+      myProp: {
+        type: Number,
+        validator(val: unknown): boolean {
+          // @ts-expect-error
+          return val !== this.otherProp
+        },
+        default(): number {
+          // @ts-expect-error
+          return this.otherProp + 1
+        }
+      },
+      otherProp: {
+        type: Number,
+        required: true
+      }
+    }
+  })
 })
 
 // describe('type inference w/ optional props declaration', () => {