-
-
Notifications
You must be signed in to change notification settings - Fork 596
wrong typing of "this" when returning concatenated string in computed #1554
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
Comments
+1 same problem on same platform |
This seems to work fine for me (annotating the return type) <template>
<div></div>
</template>
<script lang="ts">
import Vue from 'vue'
export default Vue.extend({
props: {
tata: {
type: String,
default: null
}
},
computed: {
titi (): string {
return 'toto' + this.tata;
}
},
mounted () {
this.$el;
},
methods: {
toto () {
console.log(this.tata);
}
}
})
</script> I guess it's somewhat related to microsoft/TypeScript#30854. Need to file a new issue in TS... |
@jbmaisner @kernZero you can use JSDoc to annotate return types of computed and fix your issue |
I can confirm, adding JSDoc annotation works. But upstream issue is closed as @DanielRosenwasser This used to work as expected and fixing this would help a lot of beginner Vue users who don't know TS. |
Can you give it a shot on TS 3.9.5? There were a few small fixes that might have helped there. |
@DanielRosenwasser I'm using <template>
<div/>
</template>
<script>
import Vue from 'vue'
export default {
props: {
tata: {
type: String,
default: null
}
},
computed: {
/**
* @returns {string}
*/
titi () {
return 'toto' + this.tata;
}
},
mounted () {
this.$el;
},
methods: {
toto () {
console.log(this.tata);
}
}
};
</script> Once you remove the JSDoc, |
I think duplicate of #1707 ? |
Duplicate of #1707. |
Uh oh!
There was an error while loading. Please reload this page.
Info
Problem
When I return a concat string + props in a computed, the keyword "this" is wrong typed in methods and lifecycle hooks. It's no more typed as "CombinedVueInstance" which causes some problems with Intellisense suggestions and type safe javascript through JSDoc.
Please see screenshots for better comprehension.
Wrong typing of keyword "this"

Correct typing of keyword "this"

Reproducible Case
You can simply insert the following code example,
Or create a SFC with any template, then in the script section, add a mounted hook and a lambda method. Finally add a computed returning a string + props.
Hover the keyword "this" in the mounted hook or in the method.
Code example
The text was updated successfully, but these errors were encountered: