Skip to content

Commit a88895b

Browse files
authored
types(runtime-core): make this void in prop validators and prop default factories (vuejs#1867)
1 parent 9d36c61 commit a88895b

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

packages/runtime-core/src/componentOptions.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ export type ComponentOptionsWithObjectProps<
217217
EE extends string = string,
218218
Props = Readonly<ExtractPropTypes<PropsOptions>>
219219
> = ComponentOptionsBase<Props, RawBindings, D, C, M, Mixin, Extends, E, EE> & {
220-
props: PropsOptions
220+
props: PropsOptions & ThisType<void>
221221
} & ThisType<
222222
CreateComponentPublicInstance<
223223
Props,

test-dts/defineComponent.test-d.tsx

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,27 @@ describe('with object props', () => {
210210
)
211211
// @ts-expect-error
212212
expectError(<MyComponent b="foo" dd={{ n: 'string' }} ddd={['foo']} />)
213+
214+
// `this` should be void inside of prop validators and prop default factories
215+
defineComponent({
216+
props: {
217+
myProp: {
218+
type: Number,
219+
validator(val: unknown): boolean {
220+
// @ts-expect-error
221+
return val !== this.otherProp
222+
},
223+
default(): number {
224+
// @ts-expect-error
225+
return this.otherProp + 1
226+
}
227+
},
228+
otherProp: {
229+
type: Number,
230+
required: true
231+
}
232+
}
233+
})
213234
})
214235

215236
// describe('type inference w/ optional props declaration', () => {

0 commit comments

Comments
 (0)