-
-
Notifications
You must be signed in to change notification settings - Fork 9.1k
Description
Version
3.0.5
Reproduction link
https://github.com/l0rn/inject-provide-types/tree/options-api
Steps to reproduce
Use the Provide/Inject mechanism using the Options API and Typescript.
Injected properties won't be inferred and will throw type errors complaining the property is not defined on the component.
On the main branch of the same repository you will find the same being achieved using composition API, which works fine.
As far as I understand only using Typescript should not be a reason to use the Composition API I think it would be a cool effort trying to add typing support to inject using the Options API. If that's not feasible I think a warning in the documentation would be appropriate.
What is expected?
Best case scenario:
- Use provide / inject in options API, all types are properly inferred
- If any additional type declaration is needed, a paragraph on inject / provide in the typescript section of the docs is provided
What is actually happening?
Using provide / inject in my typescript code, wondering why the injected property is not available in typescript:
ERROR in src/components/Marker.vue:23:19
TS2339: Property 'map' does not exist on type 'ComponentPublicInstance<Readonly<{ location: LocationDto; } & {}>, {}, {}, {}, {}, Record<string, any>, Readonly<{ location: LocationDto; } & {}>, {}, false, ComponentOptionsBase<...>>'.
21 | marker
22 | .setLngLat([this.location.lng, this.location.lat])
> 23 | .addTo(this.map.value)
| ^^^
24 |
25 | }
26 | })