utilities icon indicating copy to clipboard operation
utilities copied to clipboard

TypeScript plugin support

Open einarq opened this issue 3 years ago • 4 comments

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 avatar Jan 18 '23 12:01 einarq

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 avatar Jan 18 '23 12:01 einarq

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?

einarq avatar Jan 18 '23 12:01 einarq

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' })

alex-vukov avatar Mar 16 '23 06:03 alex-vukov