knitkit types generate (run on the remote) and knitkit types sync (run on the host). Together
they produce a declare module "@knitkit/runtime" block that augments the RemoteModules
interface, so loadRemote("checkout/CartWidget") resolves to the exact type that the
checkout remote’s CartWidget module exports — no manual type stubs required.
On the remote
Run these steps once after each build, or wire them into your remote’s CI pipeline.1
Build first, then generate types
Run your normal build, then immediately run the types command. The command writes one
knitkit types generate
reads dist/knit.manifest.json and uses your project’s locally installed typescript
compiler to emit declaration files.typescript is an optional peer dependency of the CLI. If it is not installed in your
project, the command throws with an actionable message: npm i -D typescript..d.ts file per exposed module into dist/types/:2
Verify the manifest carries types paths
After running The host’s
knitkit types generate, the manifest’s exposes entries now include a
"types" field pointing at each generated declaration:knitkit types sync command reads this "types" field to know what to
download.On the host
Run these steps whenever a remote’s types change, or schedule them as part of your CI pre-build step.1
Create knit.host.json
Add a
knit.host.json file at your project root. List every remote your host consumes and
configure the output directory for downloaded declarations:"typesDir" defaults to ".knitkit/types" if omitted.2
Run knitkit types sync
- Fetches each remote manifest listed in
knit.host.json - For every expose that has a
"types"field, downloads the.d.tsfile into<typesDir>/<remoteName>/<exposeKey>.d.ts - Generates
<typesDir>/knitkit-remotes.d.ts— a module augmentation that wires every remote specifier to its downloaded declaration type
3
Add the types directory to tsconfig.json
TypeScript needs to see the generated directory. Add it to the
include array in your
tsconfig.json:4
Enjoy fully typed loadRemote() calls
With the augmentation in place,
loadRemote resolves to the exact type the remote exports:How augmentation works
knitkit types sync generates a file that augments @knitkit/runtime’s exported
RemoteModules interface. The generated knitkit-remotes.d.ts looks like this:
RemoteModules interface is the single source of truth for loadRemote’s return type.
When your loadRemote("checkout/CartWidget") call resolves, TypeScript looks up
RemoteModules["checkout/CartWidget"] and uses that as the return type — giving you
auto-complete on props, refactoring support, and compile-time safety on specifier strings.
knit.host.json fields
Array<{ name: string; manifest: string }>
required
Each entry names the remote and provides the URL (or local path) to its
knit.manifest.json. The name must match what you pass to registerRemotes.string
Directory (relative to
knit.host.json) where declarations are written. Defaults to
".knitkit/types".