Skip to content

Commit a74011a

Browse files
authored
types(defineComponent): fix options API support when using defineComponent (#610)
1 parent 97461c7 commit a74011a

File tree

2 files changed

+51
-7
lines changed

2 files changed

+51
-7
lines changed

src/component/componentProxy.ts

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,19 @@ export type ComponentRenderProxy<
4141
Omit<Vue, '$data' | '$props' | '$attrs'>
4242

4343
// for Vetur and TSX support
44-
type VueConstructorProxy<PropsOptions, RawBindings> = VueConstructor & {
44+
type VueConstructorProxy<
45+
PropsOptions,
46+
RawBindings,
47+
Data,
48+
Computed extends ComputedOptions,
49+
Methods extends MethodOptions
50+
> = VueConstructor & {
4551
new (...args: any[]): ComponentRenderProxy<
4652
ExtractPropTypes<PropsOptions>,
4753
ShallowUnwrapRef<RawBindings>,
48-
ExtractPropTypes<PropsOptions>,
49-
{},
50-
{},
54+
Data,
55+
Computed,
56+
Methods,
5157
ExtractPropTypes<PropsOptions>,
5258
ExtractDefaultPropTypes<PropsOptions>,
5359
true
@@ -62,8 +68,8 @@ export type VueProxy<
6268
PropsOptions,
6369
RawBindings,
6470
Data = DefaultData<Vue>,
65-
Computed = DefaultComputed,
66-
Methods = DefaultMethods<Vue>
71+
Computed extends ComputedOptions = DefaultComputed,
72+
Methods extends MethodOptions = DefaultMethods<Vue>
6773
> = Vue2ComponentOptions<
6874
Vue,
6975
ShallowUnwrapRef<RawBindings> & Data,
@@ -72,4 +78,4 @@ export type VueProxy<
7278
PropsOptions,
7379
ExtractPropTypes<PropsOptions>
7480
> &
75-
VueConstructorProxy<PropsOptions, RawBindings>
81+
VueConstructorProxy<PropsOptions, RawBindings, Data, Computed, Methods>

test-dts/defineComponent.test-d.ts

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -667,3 +667,41 @@ describe('emits', () => {
667667
})
668668
*/
669669
})
670+
671+
describe('vetur', () => {
672+
// #609
673+
it('should have access to options API', () => {
674+
const Comp = defineComponent({
675+
data() {
676+
return {
677+
a: 1,
678+
}
679+
},
680+
681+
computed: {
682+
ac() {
683+
return 1
684+
},
685+
},
686+
687+
methods: {
688+
callA(b: number) {
689+
return b
690+
},
691+
},
692+
693+
setup() {
694+
return {
695+
sa: '1',
696+
}
697+
},
698+
})
699+
700+
const comp = new Comp()
701+
702+
expectType<number>(comp.a)
703+
expectType<number>(comp.ac)
704+
expectType<string>(comp.sa)
705+
expectType<(b: number) => number>(comp.callA)
706+
})
707+
})

0 commit comments

Comments
 (0)