Skip to content

Commit 4821149

Browse files
ktsnyyx990803
authored andcommitted
fix(types): fix prop constructor type inference (vuejs#10779)
1 parent 9f5563c commit 4821149

File tree

4 files changed

+29
-25
lines changed

4 files changed

+29
-25
lines changed

package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@
7474
"@babel/plugin-transform-flow-strip-types": "^7.0.0",
7575
"@babel/preset-env": "^7.0.0",
7676
"@babel/register": "^7.0.0",
77-
"@types/node": "^10.12.18",
77+
"@types/node": "^12.12.0",
7878
"@types/webpack": "^4.4.22",
7979
"acorn": "^5.2.1",
8080
"babel-eslint": "^10.0.1",
@@ -136,7 +136,7 @@
136136
"serialize-javascript": "^1.3.0",
137137
"shelljs": "^0.8.1",
138138
"terser": "^3.10.2",
139-
"typescript": "^3.1.3",
139+
"typescript": "^3.6.4",
140140
"webpack": "~4.28.4",
141141
"weex-js-runtime": "^0.23.6",
142142
"weex-styler": "^0.3.0",

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 } | { new(...args: never[]): T & object } | { new(...args: string[]): Function }
148148

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

types/test/options-test.ts

+16-17
Original file line numberDiff line numberDiff line change
@@ -90,21 +90,20 @@ Vue.component('union-prop', {
9090
}
9191
});
9292

93-
// stopped working since TS 3.4
94-
// Vue.component('union-prop-with-no-casting', {
95-
// props: {
96-
// mixed: [RegExp, Array],
97-
// object: [Cat, User],
98-
// primitive: [String, Number],
99-
// regex: RegExp
100-
// },
101-
// data() {
102-
// this.mixed;
103-
// this.object;
104-
// this.primitive;
105-
// this.regex.compile;
106-
// }
107-
// })
93+
Vue.component('union-prop-with-no-casting', {
94+
props: {
95+
mixed: [RegExp, Array],
96+
object: [Cat, User],
97+
primitive: [String, Number],
98+
regex: RegExp
99+
},
100+
data() {
101+
this.mixed;
102+
this.object;
103+
this.primitive;
104+
this.regex.compile;
105+
}
106+
})
108107

109108
Vue.component('prop-with-primitive-default', {
110109
props: {
@@ -113,7 +112,7 @@ Vue.component('prop-with-primitive-default', {
113112
default: () => String(Math.round(Math.random() * 10000000))
114113
}
115114
},
116-
created() {
115+
created(): void {
117116
this.id;
118117
}
119118
});
@@ -152,7 +151,7 @@ Vue.component('component', {
152151
}
153152
},
154153
methods: {
155-
plus() {
154+
plus(): void {
156155
this.a++;
157156
this.aDouble.toFixed();
158157
this.aPlus = 1;

yarn.lock

+10-5
Original file line numberDiff line numberDiff line change
@@ -675,11 +675,16 @@
675675
resolved "https://registry.yarnpkg.com/@types/estree/-/estree-0.0.39.tgz#e177e699ee1b8c22d23174caaa7422644389509f"
676676
integrity sha512-EYNwp3bU+98cpU4lAWYYL7Zz+2gryWH1qbdDTidVd6hkiR6weksdbMadyXKXNPEkQFhXM+hVO9ZygomHXp+AIw==
677677

678-
"@types/node@*", "@types/node@^10.12.18":
678+
"@types/node@*":
679679
version "10.12.18"
680680
resolved "https://registry.yarnpkg.com/@types/node/-/node-10.12.18.tgz#1d3ca764718915584fcd9f6344621b7672665c67"
681681
integrity sha512-fh+pAqt4xRzPfqA6eh3Z2y6fyZavRIumvjhaCL753+TVkGKGhpPeyrJG2JftD0T9q4GF00KjefsQ+PQNDdWQaQ==
682682

683+
"@types/node@^12.12.0":
684+
version "12.12.0"
685+
resolved "https://registry.yarnpkg.com/@types/node/-/node-12.12.0.tgz#ff3201972d6dc851a9275308a17b9b5094e68057"
686+
integrity sha512-6N8Sa5AaENRtJnpKXZgvc119PKxT1Lk9VPy4kfT8JF23tIe1qDfaGkBR2DRKJFIA7NptMz+fps//C6aLi1Uoug==
687+
683688
"@types/tapable@*":
684689
version "1.0.4"
685690
resolved "https://registry.yarnpkg.com/@types/tapable/-/tapable-1.0.4.tgz#b4ffc7dc97b498c969b360a41eee247f82616370"
@@ -7927,10 +7932,10 @@ typedarray@^0.0.6:
79277932
resolved "https://registry.yarnpkg.com/typedarray/-/typedarray-0.0.6.tgz#867ac74e3864187b1d3d47d996a78ec5c8830777"
79287933
integrity sha1-hnrHTjhkGHsdPUfZlqeOxciDB3c=
79297934

7930-
typescript@^3.1.3:
7931-
version "3.2.2"
7932-
resolved "https://registry.yarnpkg.com/typescript/-/typescript-3.2.2.tgz#fe8101c46aa123f8353523ebdcf5730c2ae493e5"
7933-
integrity sha512-VCj5UiSyHBjwfYacmDuc/NOk4QQixbE+Wn7MFJuS0nRuPQbof132Pw4u53dm264O8LPc2MVsc7RJNml5szurkg==
7935+
typescript@^3.6.4:
7936+
version "3.6.4"
7937+
resolved "https://registry.yarnpkg.com/typescript/-/typescript-3.6.4.tgz#b18752bb3792bc1a0281335f7f6ebf1bbfc5b91d"
7938+
integrity sha512-unoCll1+l+YK4i4F8f22TaNVPRHcD9PA3yCuZ8g5e0qGqlVlJ/8FSateOLLSagn+Yg5+ZwuPkL8LFUc0Jcvksg==
79347939

79357940
uglify-js@^3.1.4:
79367941
version "3.6.1"

0 commit comments

Comments
 (0)