From 791f5aa75959250117ae2b2f15a3c91b68f16e5d Mon Sep 17 00:00:00 2001 From: Francois Hendriks Date: Mon, 27 May 2019 17:31:50 +0200 Subject: [PATCH] fix(TypeScript): Force ArrayConstructor to be a any[] typescript type When using an Array prop in a Vue component with TypeScript, typescript breaks because the JavaScript arrayconstructor is transpiled to a {}[] typescript type that is for some reason more general than any[]. Since the type is more general, the component is not using the correct component overload function declaration. The idea here is to force the JavaScript ArrayConstructor to be transpiled to any[] type. fix #9935 --- types/options.d.ts | 2 +- types/test/options-test.ts | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/types/options.d.ts b/types/options.d.ts index 3fe7a9b7aaf..f9da73f9ee9 100644 --- a/types/options.d.ts +++ b/types/options.d.ts @@ -144,7 +144,7 @@ export interface RenderContext { injections: any } -export type Prop = { (): T } | { new(...args: any[]): T & object } | { new(...args: string[]): Function } +export type Prop = { (): T extends {}[] ? any[] : T } | { new(...args: any[]): T & object } | { new(...args: string[]): Function } export type PropType = Prop | Prop[]; diff --git a/types/test/options-test.ts b/types/test/options-test.ts index 28060b7c817..a62a02b5987 100644 --- a/types/test/options-test.ts +++ b/types/test/options-test.ts @@ -118,6 +118,25 @@ Vue.component('prop-with-primitive-default', { } }); +// Test issue with the Array prop type +Vue.extend({ + props: { + s: String, + a: {type: Array}, + b: Boolean + }, + created() { + console.log(this.a) + console.log(this.s) + console.log(this.b) + }, + mounted() { + console.log(this.a) + console.log(this.s) + console.log(this.b) + } +}) + Vue.component('component', { data() { this.$mount