DEV Community

Discussion on: Micro-frontends: Module Federation with WebPack 5

deexter profile image

What if my MF accepts some props?
Is there possibility to expose types for typescript?
Or is this bad practise and MF has to be without props?

alexvukov profile image
alex-vukov • Edited on

It's bad practice to use typescript... But joke aside, you can pass whatever props you like to your MF component. Problem is you can't import typescript interfaces from a remote application which is already compiled to javascript because they don't exist in it. You have three options. (1)Create an extra npm package containing only ts interfaces and import it into the consumer app, (2)create a .ts interface locally in the consumer app or (3)expose another extra module from the MF which contains react prop-types for the actual component which you will use. Then in your consumer application you can import both the remote prop-types and the remote component and pass data in the shape of the prop-types object to it. Prop-types exist during runtime so in theory it will work.