Skip to content

Repository files navigation

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 its logicType.ts file. 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 obsolete logicType.ts files are removed on conversion.
  • Untyped selector combiner parameters get their types written into the source, since MakeLogicType types them as any. 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 a logicMeta interface. kea 4 takes it as the fourth MakeLogicType type argument; on kea 3, whose MakeLogicType has 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 connect are 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.

About

No description, website, or topics provided.

Resources

Stars

6 stars

Watchers

2 watching

Forks

Releases

Packages

Used by

Contributors

Languages