https://codesandbox.io/p/devbox/gq2qss?file=%2Fremotes.d.ts
We're using module federation and import from remote containers at run time.
To provide type safety, we use types from the packages that provide remote containers, and re-export those types through typescript module declaration, so that the types match the names of federated containers as defined in federation configuration:
// This module name is used in module federation configuration
declare module "@my/remote-container" {
// This is a type-only re-export from a package that
// provides a remote container from module federation
export * from "actual-remote-container-package";
}
In another file:
// This import works in real setup only at runtime,
// because it refers to a remote container from module federation
import {SomeThing} from '@my/remote-container';
SomeThing.foo();
With this setup knip
reports both the package used to export types from under declare module
as "Unused" and the import from the declared module as "Unlisted":
> knip
Unused devDependencies (1)
actual-remote-container-package package.json
Unlisted dependencies (1)
@my/remote-container index.ts
Pay now to fund the work behind this issue.
Get updates on progress being made.
Maintainer is rewarded once the issue is completed.
You're funding impactful open source efforts
You want to contribute to this effort
You want to get funding like this too