Skip to content

fix(types): this type in data(), fix #570 #576

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 2, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 4 additions & 7 deletions src/component/componentOptions.ts
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
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