Inject a prop into a component via the inject option
Try to reference the injected prop from a method/computed/data.
<scriptlang="ts">import{defineComponent}from'vue'exportdefaultdefineComponent({inject: ['msg'],computed: {computedMsg(){// FIXME: TypeScript doesn't see the prop from inject optionreturnthis.msg+'!'^^^}}})</script>
What is expected?
The injected prop is available in other options, including methods and computed.
What is actually happening?
TypeScript shows this error:
Property 'msg' does not exist on type 'ComponentPublicInstance<{}, {}, {}, { computedMsg(): string; }, {}, EmitsOptions, {}, {}, false, ComponentOptionsBase<{}, {}, {}, { computedMsg(): string; }, {}, ComponentOptionsMixin, ComponentOptionsMixin, EmitsOptions, string, {}>>'
Link to minimal reproduction
https://stackblitz.com/edit/vitejs-vite-ycsdst?file=src%2Fcomponents%2FMyComponent.vue,src%2FApp.vue
Steps to reproduce
inject
optionWhat is expected?
The injected prop is available in other options, including
methods
andcomputed
.What is actually happening?
TypeScript shows this error:
System Info
Any additional comments?
Also happens with Vue CLI scaffolded project.
The text was updated successfully, but these errors were encountered: