### Investigate better type support for remote apps
#### Option 1: `@module-federation/typescript` package
1. Run `npm i @module-federation/typescript`
2. Register the plugin in webpack configuration (webpack.config.js) file (both host and remote)
```
const { FederatedTypesPlugin } = require('@module-federation/typescript');
...
module.exports = composePlugins(
...
(config) => {
...
config.plugins.push(
new FederatedTypesPlugin({
federationConfig: {
...baseConfig
})
);
...
return config;
}
);
```
3. Update the `compilerOptions` in `tsconfig.app.json` in the host app and added the following as per the docs
```
{
"compilerOptions": {
...
"baseUrl": ".",
"paths": {
"*": ["./@mf-types/*"]
}
}
}
```
Supposedly this plugin creates this `@mf-types` folder but that has yet to happen.
I ran into a few issues until getting here:
- `FederatedTypesPlugin is not a constructor` - happened because the old docs say to import the plugin this way `const FederatedTypesPlugin = require('@module-federation/typescript');`
- `Cannot read properties of undefined (reading 'filename')` - happened because I was using the wrong syntax for the plugin
```
# incorrect
config.plugins.push(
new FederatedTypesPlugin({
...baseConfig,
})
);
#correct
config.plugins.push(
new FederatedTypesPlugin({
federationConfig: {
...baseConfig,
},
})
);
```
Then I started to encounter a lot of these errors
- `[FederatedTypesPlugin] Unable to download 'guided-recommenders-mfe' remote types index file AxiosError: connect ECONNREFUSED 0.0.0.0:3003`
- `[FederatedTypesPlugin] Error: something went wrong generating declaration files`
Adding this to the webpack.config.js files helped to log the actual error messages
```
config.infrastructureLogging = { debug: /FederatedTypesPlugin/ };
```
This is currently giving me a couple of different errors for `browse-projects-mfe`, `guided-recommenders-mfe`, and `spa-remote-app`:
- `Exported variable 'X' has or is using name 'Y' from external module "Z" but cannot be named.`
- `Property 'X' of exported interface has or is using private name 'Y'.`
I could resolve these errors by exporting the affected types.