From a35621d404abebc32473cc6cdbc732d03900edeb Mon Sep 17 00:00:00 2001 From: yoyo930021 Date: Mon, 23 Mar 2020 16:23:57 +0800 Subject: [PATCH] fix(types): fix type when computed return about this --- types/options.d.ts | 2 +- types/test/options-test.ts | 28 ++++++++++++++++++++++++++++ 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/types/options.d.ts b/types/options.d.ts index f49ca085e4e..0601e5613cf 100644 --- a/types/options.d.ts +++ b/types/options.d.ts @@ -61,7 +61,7 @@ export type ThisTypedComponentOptionsWithRecordProps>>; type DefaultData = object | ((this: V) => object); -type DefaultProps = Record; +type DefaultProps = {}; type DefaultMethods = { [key: string]: (this: V, ...args: any[]) => any }; type DefaultComputed = { [key: string]: any }; export interface ComponentOptions< diff --git a/types/test/options-test.ts b/types/test/options-test.ts index fb06abb583b..d6cf778faec 100644 --- a/types/test/options-test.ts +++ b/types/test/options-test.ts @@ -105,6 +105,34 @@ Vue.component('union-prop-with-no-casting', { } }) +Vue.component('union-prop-with-no-casting-and-computed-return-this', { + props: { + mixed: [RegExp, Array], + object: [Cat, User], + primitive: [String, Number], + regex: RegExp + }, + data() { + this.mixed; + this.object; + this.primitive; + this.regex.compile; + }, + computed: { + returnThis () { + this + return this.mixed + } + }, + methods: { + hello() { + console.log(this.mixed); + console.log(this.returnThis) + return 0 + } + }, +}) + Vue.component('prop-with-primitive-default', { props: { id: {