module-federation / utilities

Various Utilities for Module Federation
MIT License
37 stars 0 forks source link

TypeScript plugin support #12

Open einarq opened 1 year ago

einarq commented 1 year ago

Does the importRemote util work with the MF typescript plugin?

Meaning, if you import a React component like this, does it also preserve any types?

importRemote({ url: "http://localhost:3001", scope: 'Foo', module: 'Bar' }).then(({/* list of Bar exports */}) => {
einarq commented 1 year ago

Btw, I came here via this issue: https://github.com/module-federation/module-federation-examples/issues/681#issuecomment-1244897249

We are trying to find the best way to actually postpone loading the remoteEntry, and other modules that it drags with it, until any module from this remote is actually needed. Currently MF has the unfortunate side-effect of pre-loading too much stuff it seems.

einarq commented 1 year ago

Also have this issue over on the external-remotes-plugin: https://github.com/module-federation/external-remotes-plugin/issues/6

That plugin is deprecated, right? Is "importRemote" the current recommendation? Or is the recommendation still to use the "promise new Promise" approach mentioned in the docs?

alex-vukov commented 1 year ago

Hi @einarq! I am just seeing this issue. Sorry for the delay. importRemote does not preserve the types from the module it imports dynamically, however it can be passed a generic type which then will be assigned to the resolved object. So you can use it like this for example importRemote<{title: string; children?:JSX.Element;}>({ url: "http://localhost:3001", scope: 'Foo', module: 'Bar' })