Closed terminalqo closed 3 years ago
This is fine.
but : https://v3.vuejs.org/guide/component-props.html#prop-validation
You should use arrow function while using validator or default attr. #2474
You should use arrow function while using validator or default attr. #2474
This answer is correct.
I'm having the same problem, but with data
instead of props
. I don't have any validators or anything like that, and it works just fine when using javascript.
<script lang="ts">
export default {
data() {
return {
platform: "x86_64"
};
},
computed: {
showMachines() {
return this.platform === "arm" || this.platform === "aarch64"; // Error here, on platform
},
showAarch64() {
return this.platform === "aarch64"; // Here too, same place
}
}
};
</script>
defineComponent()
to let TS know you are actually defining a Vue componentshowMachines(): boolean {
For more help, please use chat.vuejs.org
I'm having the same problem, but with
data
instead ofprops
. I don't have any validators or anything like that, and it works just fine when using javascript.<script lang="ts"> export default { data() { return { platform: "x86_64" }; }, computed: { showMachines() { return this.platform === "arm" || this.platform === "aarch64"; // Error here, on platform }, showAarch64() { return this.platform === "aarch64"; // Here too, same place } } }; </script>
The same problem with you. It's confused.
@ravenclaw900 @bobohuochai as @LinusBorg point as soon you define the return types of your computed properties the types from the data properties will work just fine(looks like not doing it breaks all the typing on the component).
- use
defineComponent()
to let TS know you are actually defining a Vue component- try annotating the return values of the computed's:
showMachines(): boolean {
For more help, please use chat.vuejs.org
thank you very much!
- use
defineComponent()
to let TS know you are actually defining a Vue component- try annotating the return values of the computed's:
showMachines(): boolean {
For more help, please use chat.vuejs.org
This works. The problem of TypeScript
I had this problem for objects that I was injecting into my component. For anyone having problems with typing injected data, the solution is to use the Composition API instead.
- use
defineComponent()
to let TS know you are actually defining a Vue component- try annotating the return values of the computed's:
showMachines(): boolean {
For more help, please use chat.vuejs.org
thanks, also correct resolve my problem, ts error with data.
Version
"vue": "^3.0.0" "eslint": "^6.7.2" "typescript": "~3.9.3" vue-cli@latest
Reproduction link
[]()
Steps to reproduce
What is expected?
No ts warning
What is actually happening?
ts warning show:
file name: BarCharts.tsx, use vscode vetur@latest.