Skip to content

Commit 9a5b438

Browse files
authored
fix(types): this type in data(), fix #570 (#576)
1 parent 00c4e16 commit 9a5b438

File tree

2 files changed

+5
-7
lines changed

2 files changed

+5
-7
lines changed

src/component/componentOptions.ts

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
1+
import { VNode, ComponentOptions as Vue2ComponentOptions } from 'vue'
12
import { Data } from './common'
23
import { ComponentPropsOptions, ExtractPropTypes } from './componentProps'
3-
import { VNode } from 'vue'
44
import { ComponentInstance, ComponentRenderProxy } from './componentProxy'
55

6-
import { ComponentOptions as Vue2ComponentOptions } from 'vue'
7-
86
export interface SetupContext {
97
readonly attrs: Record<string, string>
108
readonly slots: { [key: string]: (...args: any[]) => VNode[] }
@@ -43,12 +41,11 @@ interface ComponentOptionsBase<
4341
D = Data,
4442
C extends ComputedOptions = {},
4543
M extends MethodOptions = {}
46-
>
47-
extends Omit<
44+
> extends Omit<
4845
Vue2ComponentOptions<Vue, D, M, C, Props>,
4946
'data' | 'computed' | 'method' | 'setup' | 'props'
5047
> {
51-
data?: (this: Props, vm: Props) => D
48+
data?: (this: Props & Vue, vm: Props) => D
5249
computed?: C
5350
methods?: M
5451
}
@@ -70,7 +67,7 @@ export type ComponentOptionsWithProps<
7067
Props = ExtractPropTypes<PropsOptions>
7168
> = ComponentOptionsBase<Props, D, C, M> & {
7269
props?: PropsOptions
73-
emits?: string[] | Record<string, null | ((emitData: any) => boolean) >
70+
emits?: string[] | Record<string, null | ((emitData: any) => boolean)>
7471
setup?: SetupFunction<Props, RawBindings>
7572
} & ThisType<ComponentRenderProxy<Props, RawBindings, D, C, M>>
7673

test-dts/defineComponent.test-d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,7 @@ describe('type inference w/ options API', () => {
242242
// Limitation: we cannot expose the return result of setup() on `this`
243243
// here in data() - somehow that would mess up the inference
244244
expectType<number | undefined>(this.a)
245+
expectType<Function>(this.$emit)
245246
return {
246247
c: this.a || 123,
247248
}

0 commit comments

Comments
 (0)