Created
August 29, 2022 21:11
-
-
Save brunos3d/d137b33eb52ba8bfec91adc59a259db0 to your computer and use it in GitHub Desktop.
How to declare federated components types with typescript module declaration
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| declare module 'remoteA/componentA' { | |
| function Component(props: unknown): JSX.Element; | |
| export default Component; | |
| } | |
| declare module 'remoteB/componentB' { | |
| export type ComponentProps = { | |
| foo: boolean; | |
| bar?: () => void; | |
| }; | |
| function Component(props: ComponentProps): JSX.Element; | |
| export default Component; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import dynamic from 'next/dynamic'; | |
| const ComponentA = dynamic(() => import('remoteA/componentA'), { ssr: true }); | |
| const ComponentB = dynamic(() => import('remoteB/componentB'), { ssr: false }); | |
| export default function Home() { | |
| return ( | |
| <main> | |
| <ComponentA /> | |
| <ComponentB foo bar={() => console.log('Hello, World!')} /> | |
| <ComponentB foo={() => console.log('Type error!')} bar /> | |
| </main> | |
| ); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment