You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
<template><div><p>
{{ joinedWords }}
</p></div></template><scriptlang="ts">import{defineComponent,PropType}from'vue';exportdefaultdefineComponent({name: 'FooBar',props: {words: {type: ArrayasPropType<string[]>,// Using default: () => [] does not trigger the bugdefault(){return[];}}},computed: {joinedWords(){// Using this.words in a computed function, method or lifecycle hook// is necessary to trigger the bugreturnthis.words.join('');}}});</script>
If you have a component with an array prop that uses method syntax for its default factory function, and that accesses that prop using this.propName in a computed property, you get a strange TypeScript error. The example above produces the following error:
FooBar.vue:27:16 - error TS2339: Property 'words' does not exist on type 'CreateComponentPublicInstance<Readonly<ExtractPropTypes<Readonly<ComponentPropsOptions<Data>>>> & { [x: string & `on${string}`]: undefined; }, ... 16 more ..., { ...; } | {}>'.
27 return this.words.join( '' );
If you use an arrow function instead of method syntax for the default factory function, the bug doesn't happen.
The Vue documentation uses method syntax in its examples for default factory functions, see propE in this code example.
The text was updated successfully, but these errors were encountered:
Minimal example:
If you have a component with an array prop that uses method syntax for its default factory function, and that accesses that prop using
this.propName
in a computed property, you get a strange TypeScript error. The example above produces the following error:If you use an arrow function instead of method syntax for the default factory function, the bug doesn't happen.
The Vue documentation uses method syntax in its examples for default factory functions, see propE in this code example.
The text was updated successfully, but these errors were encountered: