Skip to content

Commit 791f5aa

Browse files
committedMay 27, 2019
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 vuejs#9935
1 parent 06d4ad4 commit 791f5aa

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed
 

‎types/options.d.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ export interface RenderContext<Props=DefaultProps> {
144144
injections: any
145145
}
146146

147-
export type Prop<T> = { (): T } | { new(...args: any[]): T & object } | { new(...args: string[]): Function }
147+
export type Prop<T> = { (): T extends {}[] ? any[] : T } | { new(...args: any[]): T & object } | { new(...args: string[]): Function }
148148

149149
export type PropType<T> = Prop<T> | Prop<T>[];
150150

‎types/test/options-test.ts

+19
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,25 @@ Vue.component('prop-with-primitive-default', {
118118
}
119119
});
120120

121+
// Test issue with the Array prop type
122+
Vue.extend({
123+
props: {
124+
s: String,
125+
a: {type: Array},
126+
b: Boolean
127+
},
128+
created() {
129+
console.log(this.a)
130+
console.log(this.s)
131+
console.log(this.b)
132+
},
133+
mounted() {
134+
console.log(this.a)
135+
console.log(this.s)
136+
console.log(this.b)
137+
}
138+
})
139+
121140
Vue.component('component', {
122141
data() {
123142
this.$mount

0 commit comments

Comments
 (0)