kea-typegen
v3.8.5
Published
Generate type definitions for kea logic
Downloads
71,987
Readme
kea-typegen
Automatically generate types for kea() calls for Kea 2.2+
Docs
https://keajs.org/docs/intro/typescript
Inline mode
By default kea-typegen writes a logicType.ts file next to each logic. In inline mode it instead writes
a marked block of plain interfaces directly above the kea() call, tied together with kea's MakeLogicType:
// Generated by kea-typegen. Update if you're an agent, ignore if you're human.
export interface counterLogicValues {
counter: number
}
export interface counterLogicActions {
increment: (amount: number) => { amount: number }
}
export type counterLogicType = MakeLogicType<counterLogicValues, counterLogicActions>
export const counterLogic = kea<counterLogicType>({ ... })--inline(CLI) or"inline": true(.kearc) — inline mode for every logic.--inline-paths a b(CLI) or"inlinePaths": ["./scenes/foo"](.kearc) — inline mode only for logic files under those paths; everything else keeps itslogicType.tsfile. Relative paths resolve against the root path. Use this to migrate a large project directory by directory.- A file that already carries a generated inline block stays inline even without either option, so
conversions never regress and single files can be converted with
kea-typegen write --inline -f <file>. - With
--delete, the now obsoletelogicType.tsfiles are removed on conversion. - Untyped selector combiner parameters get their types written into the source, since
MakeLogicTypetypes them asany. An input that is one of the logic's own values indexes the generated interface ((counter) => ...becomes(counter: counterLogicValues['counter']) => ...), so the annotation follows the block on every regeneration; other inputs get their inferred type ((id: number) => ...). - Logic metadata (
key,sharedListeners, reducer actions from other logics, kea-forms input, ...) goes into alogicMetainterface. kea 4 takes it as the fourthMakeLogicTypetype argument; on kea 3, whoseMakeLogicTypehas three, it is intersected instead:MakeLogicType<V, A, P> & logicMeta. The shape is picked from the kea your project resolves. - Values and actions pulled in via
connectare marked with their source logic, e.g.user: UserType | null // userLogic, and sorted: connected entries first, grouped by source logic (groups and entries alphabetical), then the logic's own entries alphabetically. - Logics manually typed with
kea<MakeLogicType<...>>()or a custom type are left alone entirely.
