kea-typegen
v3.8.3
Published
Generate type definitions for kea logic
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 inferred types written into the source
(
(counter) => ...becomes(counter: number) => ...), sinceMakeLogicTypetypes them asany. - 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.
