-
-
Notifications
You must be signed in to change notification settings - Fork 234
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
Document typescript for cross microfrontend imports. #361
Comments
From single-spa/single-spa#609 (comment):
This comment by HB on the single-spa Slack also seems worth incorporating in some way:
|
Just used this as well for a new TS-based MFE. I also had success with using TS to generate types for our component styleguide (that wasn't even written in TS nor does it have JSDoc! Both worked; the installation method worked better as far as actually doing type checking, while the |
see this also: microsoft/TypeScript#28985 (comment) my thoughts are maybe TS could support a remote def file, which you could update as part of your CI process. |
Im struggeling with getting declarations with the default TS utility create single spa module. How come? It builds but does not produce any *.d.ts files. So why does it not output by default? |
@vongohren webpack-config-single-spa-ts uses babel-loader and fork-ts-checker-webpack-plugin, neither of which emit declaration files. I'm open to this being added to create-single-spa, but it's not there currently. You can get your project to emit types by adding compilerOptions.emitDeclarationOnly to your tsconfig.json, then adding an npm script to your package.json: // package.json
{
"scripts": {
"build": "webpack --mode=production && tsc"
}
} // tsconfig.json
{
"compilerOptions": {
"emitDeclarationOnly" true
}
} |
@joeldenning thanks yeah I got the declarations out, but I guess it should maybe be default when choosing utility module with typescript |
I agree it should be there by default. Could you open an issue on create-single-spa for it? If you have interest in contributing to create-single-spa, that would be appreciated, too. |
Created |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This issue is for Typescript integration with MFEs in single-spa; please keep the discussion to that topic. |
Also, here's a related issue in the module federation repo for the same type of thing: module-federation/module-federation-examples#20 |
I got the typescript working with MFE imports, but it failed Jest unit tests, example error "Cannot find module '@testytest/utility-module' from 'testyfeature/some.component.tsx". This utility module wasn't published, I am just running it locally. how do I fix this? |
Resolved. Since I didn't publish the module I had to mock it similar to this, https://github.com/openmrs/openmrs-esm-login/blob/518c1b1212384165fc14c1c353d3b882d99aa957/jest.config.json#L6 |
Is there a way to support typing for the returned object (e.g. through exported interface from another file). If I try to import anything into the type file where I declare the utility module, the utility module will be no longer recognized in places where it is used. |
I tried some things out, but eventually came back to the basics to get TS working with cross-MFE import: using NPM to publish only the types, and installing them locally via NPM. I did some prototyping with custom-built solutions, but just publishing types to NPM was the easiest to implement and support. |
Yeah we have done that aswell. But I do believe there might be some adjustments to the default way a single spa is instantiated, as its not straight forward to get the types out of the application. There could be some improvements on the template and potentially docs |
build sharing module by system format, then join the js in import-map.json and System.import('@module/share'); |
|
I just get "Module not found: Error: Can't resolve" I've set up the module in the system.imports. But I'm using typescript which is trying to compile the imports before runtime, so it seems like this would never work with typescript? Or does someone have a working example? Because I haven't seen a single working example of a single spa utility module using typescript |
This comment and this comment have resources to help you. |
I tried what's in the first comment. Doesn't appear to work on it's own. That second comment just says "I got the typescript working with MFE imports" without an explanation of how. Only an explanation of how they got it working with Jest |
Any updates ? |
No description provided.
The text was updated successfully, but these errors were encountered: