-
-
Notifications
You must be signed in to change notification settings - Fork 33.7k
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
Typing: Props not bound to this
#9935
Comments
Perhaps a duplicate of #9873 Both root causes seem to be from this TypeScript issue: microsoft/TypeScript#30854 |
It is clear how to fix this in case of computed properties, but what should we do in this case? |
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
I had this issue a couple of times. This is mostly caused by the No errors using the following script: import Vue from 'vue'
const foo = Vue.extend({
props: {
a: Array as () => any[],
s: String,
b: Boolean
},
created() {
console.log(this.a)
console.log(this.s)
console.log(this.b)
}
}) I think this is only working with TS <= 3.3.4000 |
@Patcher56 Indeed ! The issue comes from the Now for some reason in the case of the My PR solves this issue by forcing the type coming from an |
For me the error occurs on not Array props too! See microsoft/TypeScript#30854 (comment) |
By the way, this issue does not appear if you test it with TypeScript 3.5 (in development). Instead of having an array typed as any[], it will be typed as unknown[], thus solving this issue. |
This issue still occurs for me, with Arrays, while using TypeScript 3.5.3 and Vue 2.6.10. @Patcher56 workaround was the only thing that fixed it. Although, incredibly, it took me hours of googling to find this solution. Hopefully @Domino9697 's PR gets merged. |
This might be related: |
This is already fixed on TypeScript >= 3.5. |
Version
Vue: 2.6.10
TS: 3.3.4000 and 3.4.5
Reproduction link
https://github.com/octref/vue-prop-type-error
Steps to reproduce
git clone https://github.com/octref/vue-prop-type-error && cd vue-prop-type-error
yarn
yarn compile
What is expected?
No error reported from this file
What is actually happening?
a
,s
,b
are not bound to this instanceThe text was updated successfully, but these errors were encountered: