-
-
Notifications
You must be signed in to change notification settings - Fork 43
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
Props with Vue3 and Typescript #86
Comments
This sounds like the typescript definitions need to be updated. Here's the file where they can be updated: https://github.com/single-spa/single-spa-vue/blob/main/types/single-spa-vue.d.ts The single-spa library has the default props defined at https://github.com/single-spa/single-spa/blob/f67d6fcd404597a246636e302f1d9e7b0f8cd9c6/typings/single-spa.d.ts#L12 - those should be imported into single-spa-vue's types and then used so that Do you have interest in contributing a pull request with the fix? |
Yea im interested and will take a closer look the next few days. Thanks for the initial ressources they look pretty helpfull! |
HI @joeldenning I think the props are already handled in single-spa-vue/types/single-spa-vue.d.ts Lines 6 to 10 in 36aa8bb
[key: string]: any; of course you could add the single-spa specific props there too (if wanted I have a PR ready).
But the real issue is the Union in line 15 onwards. single-spa-vue/types/single-spa-vue.d.ts Lines 13 to 19 in 36aa8bb
This leads understandably to the errors. Tbh I would recommend updating https://github.com/single-spa/vue-cli-plugin-single-spa/blob/18e92aa559b489128edda8a5675f839e8022a267/template/src/main-vue-3.js#L12-L19 for Typescript configs updating the occurrences of this (from line 16-18) with a typecast like this: (<AppOptions>this).singleSpa .
I don't know if this is the preferred way. If yes I would be happy to contribute these changes. tldr. Proposed Changes:
|
I think the best solution would be to type the The first thing to try would be to add the single-spa-vue/types/single-spa-vue.d.ts Lines 6 to 10 in 36aa8bb
+ import { AppProps } from 'single-spa';
+
type AppOptions = {
el?: string | HTMLElement;
data?: any;
+ render: (this: AppProps) => any;
[key: string]: any;
}; Since |
I have exactly the same issue. :( |
Hi,
I had a go on migrating some of our Vue2 Microfrontends to Vue3.
Also, I threw Typescript into the mix.
I'm not sure if it's an issue with the Package itself or just a missing bit of the documentation.
I encountered a problem with the usage of props. The SingleSpaOptsVue3 type doesn't have the props defined to typescript won't compile it. This is of course Typescript exclusive
It can easily be fixed with an this alis (which is kind of ugly and talint doesn't like):
Using
appOptions
as an async function works of course (with some types on the props).Maybe this should be described a bit better in the Docs? Or also improved in the generation? The example Comment suggesting to uncomment the Props is a bit wrong if Typescript is in place.
The text was updated successfully, but these errors were encountered: