Skip to content

Instantly share code, notes, and snippets.

@brunos3d
Created August 29, 2022 21:11
Show Gist options
  • Select an option

  • Save brunos3d/d137b33eb52ba8bfec91adc59a259db0 to your computer and use it in GitHub Desktop.

Select an option

Save brunos3d/d137b33eb52ba8bfec91adc59a259db0 to your computer and use it in GitHub Desktop.
How to declare federated components types with typescript module declaration
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;
}
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