Knit UI
GitHub

TypeScript

The kit is written in TypeScript and types are part of the API: token props are unions, not string, so p="md" autocompletes and p="medium" is a compile error.

The kit's config sets Tamagui's allowedStyleValues: "somewhat-strict-web", so a leftover v2 spelling such as p="$md" is a type error too — after an upgrade, tsc is the list of what is left to migrate.

The augmentation

Tamagui learns the kit's vocabulary through a declare module augmentation on @tamagui/core. It ships from @knitui/core as a type-only export:

import type { AppConfig } from "@knitui/core";

Nothing on the barrel imports that module at runtime — a value re-export would eagerly evaluate the Tamagui config at module load, which is a known SSR module-eval hazard. That is why it is export type.

You do not normally write this import yourself; it is reachable from @knitui/core's own declarations. If your editor stops offering md and starts accepting any string, something has broken the resolution of @knitui/core's types — check that your paths/moduleResolution let it resolve, and that you are not shadowing it with a stale build.

What is typed

SurfaceType
Space / size / radius / font props"xxs" | "xs" | … | "xxl" plus numbers, as flat values
Colour propstheme tokens (color1…color12, background, borderColor, …)
themethe registered theme names
sizeSizeKey — xxs … xxl
variantthe component's own variant union
stylesSlotStyles<XStyles> — keys checked against that component's slots

Flat values

Every style prop is typed as a flat value: the token union, or a clause string ("color2 hover:color3"), or the object form ({ default: "color2", hover: "color3" }). The type is exported as FlatStyleValue from @knitui/core.

TypeScript completes the token union and each bare modifier prefix (hover:, gtMd:, dark:), but not every combination of the two — that union would be far too large — so a misspelled payload inside a clause string is not always caught. Use the object form when you want every part checked.

Two typing caveats in Tamagui 3.0.x:

  • Only colour props accept theme keys and config variable names in their types. outlineColor="focus-visible:focusRingColor" type-checks; outlineWidth="focusRingWidth" does not, so write the number (FOCUS_RING_VARIABLES.focusRingWidth, exported by @knitui/core).
  • Variant props are flat values too, so size="sm gtMd:lg" is valid on every kit component.

Shorthands

The kit registers shorthand props (p, px, mx, bg, c, br, maw, …). They are typed exactly like their long forms:

<Box p="md" px="lg" bg="color2" br="sm" maw={480} />

Refs

Prefer the kit's element type over a DOM type — the same component is a native view on device:

import type { TamaguiElement } from "@knitui/core";

const ref = useRef<TamaguiElement>(null);

Use a real DOM type only where the thing genuinely is a DOM node on the web (FileButton's hidden <input>, web-only event handlers).

Typing your own components

styleable() from @knitui/core takes the full public props as its generic, and GetProps<typeof X> returns exactly that type:

import { styleable, type GetProps } from "@knitui/core";

interface ChipProps extends GetProps<typeof ChipFrame> {
  onToggle?: () => void;
}

export const Chip = styleable<ChipProps>(ChipFrame, function Chip(props, ref) {
  const { onToggle, ...rest } = props;
  return <ChipFrame ref={ref} onPress={onToggle} {...rest} />;
});

The ref element defaults to TamaguiElement; pass a second generic for other hosts (styleable<P, R>(Frame, …)). See styled().

Generic components

A few components are generic over their value. Accordion narrows on multiple:

<Accordion value="one" onChange={(value: string | null) => {}} />
<Accordion multiple value={["one"]} onChange={(value: string[]) => {}} />

Select, MultiSelect, Combobox and TreeSelect are generic over their item type, so onChange gives you your own objects back rather than unknown.

Strictness

The kit is built with strict: true and expects consumers to be. If you are not, things still work — you just lose the narrowing that makes token props useful.

Edit this page on GitHub