Skip to content

Commit

Permalink
fix(types): this type in data(), fix #570 (#576)
Browse files Browse the repository at this point in the history
  • Loading branch information
antfu committed Nov 2, 2020
1 parent 00c4e16 commit 9a5b438
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 7 deletions.
11 changes: 4 additions & 7 deletions src/component/componentOptions.ts
@@ -1,10 +1,8 @@
import { VNode, ComponentOptions as Vue2ComponentOptions } from 'vue'
import { Data } from './common'
import { ComponentPropsOptions, ExtractPropTypes } from './componentProps'
import { VNode } from 'vue'
import { ComponentInstance, ComponentRenderProxy } from './componentProxy'

import { ComponentOptions as Vue2ComponentOptions } from 'vue'

export interface SetupContext {
readonly attrs: Record<string, string>
readonly slots: { [key: string]: (...args: any[]) => VNode[] }
Expand Down Expand Up @@ -43,12 +41,11 @@ interface ComponentOptionsBase<
D = Data,
C extends ComputedOptions = {},
M extends MethodOptions = {}
>
extends Omit<
> extends Omit<
Vue2ComponentOptions<Vue, D, M, C, Props>,
'data' | 'computed' | 'method' | 'setup' | 'props'
> {
data?: (this: Props, vm: Props) => D
data?: (this: Props & Vue, vm: Props) => D
computed?: C
methods?: M
}
Expand All @@ -70,7 +67,7 @@ export type ComponentOptionsWithProps<
Props = ExtractPropTypes<PropsOptions>
> = ComponentOptionsBase<Props, D, C, M> & {
props?: PropsOptions
emits?: string[] | Record<string, null | ((emitData: any) => boolean) >
emits?: string[] | Record<string, null | ((emitData: any) => boolean)>
setup?: SetupFunction<Props, RawBindings>
} & ThisType<ComponentRenderProxy<Props, RawBindings, D, C, M>>

Expand Down
1 change: 1 addition & 0 deletions test-dts/defineComponent.test-d.ts
Expand Up @@ -242,6 +242,7 @@ describe('type inference w/ options API', () => {
// Limitation: we cannot expose the return result of setup() on `this`
// here in data() - somehow that would mess up the inference
expectType<number | undefined>(this.a)
expectType<Function>(this.$emit)
return {
c: this.a || 123,
}
Expand Down

0 comments on commit 9a5b438

Please sign in to comment.