# Types and generics

> Props types can live in their own files, a child's module or a package, components can be generic, and exported types reach consumers in every framework.

Types let a component tell the people who use it what it accepts, and let their editor catch a mistake before anyone runs the page. A design system keeps them apart from the components: a `ButtonProps` in a shared file, a `Tone` that several components read, a list typed by the items it's given. Think of a props interface copied into every component that needs it until two copies disagree, a list whose `selected` item can be anything at all, or a consumer who passes `tone="danger"` to a button that has no such tone and only finds out in the browser.

This page walks you through the types Unframework reads and what each framework's output does with them. We'll look at:

- **Props types from other files:** a `.ts` module, a child's module or a package.
- **What the compiler reads:** `extends`, intersections, the five utility types, and what stays out.
- **Generic components:** `function List<T>`, in each framework's own generic form.
- **Exported types:** what a consumer imports, and how it's checked.

## Props types from other files

A component's props type can come from a relative `.ts` module, as a design system declares them:

<!-- prettier-ignore -->
```ts [types.ts]
// The props of `Badge`, declared in a module of their own, as a design system declares them.
export interface BadgeProps {
  /** The text the badge shows. */
  label: string;
  tone?: "info" | "danger";
}
```

<!-- prettier-ignore -->
```tsx [Badge.uf.tsx]
import type { BadgeProps } from "./types";

export default function Badge({ label, tone = "info" }: BadgeProps) {
  return <span class={`badge badge-${tone}`}>{label}</span>;
}
```

The compiler reads the members through its type oracle, so it knows that `label` is a required string and `tone` an optional literal union with a default. Each output imports `BadgeProps` by name, rather than printing its members again, so your editor shows the type you wrote, with its comments:

::framework-switcher

#react

<!-- prettier-ignore -->
```tsx [Badge.tsx]
import type { BadgeProps } from "./types";
import type { CSSProperties } from "react";

export interface BadgeAttributes {
  className?: string;
  style?: CSSProperties;
}

export default function Badge({
  label,
  tone = "info",
  className,
  style,
  ...attributes
}: BadgeProps & BadgeAttributes) {
  return (
    <span
      className={cx(`badge badge-${tone}`, className)}
      style={style}
      {...scopeAttributes(attributes)}
    >
      {label}
    </span>
  );
}

/** Joins class names, and the keys of an object's truthy entries, into one `className`. */
function cx(...parts: unknown[]): string {
  const names: string[] = [];
  for (const part of parts) {
    if (typeof part === "string") {
      if (part) names.push(part);
    } else if (part && typeof part === "object") {
      for (const [key, on] of Object.entries(part)) {
        if (on) names.push(key);
      }
    }
  }
  return names.join(" ");
}

/** The scope attributes of the styled parents that render this component, for its root. */
function scopeAttributes(props: object): Record<string, ""> {
  const scope: Record<string, ""> = {};
  for (const key of Object.keys(props)) {
    if (key.startsWith("data-uf-")) scope[key] = "";
  }
  return scope;
}
```

#vue

<!-- prettier-ignore -->
```vue [Badge.vue]
<script setup lang="ts">
import type { BadgeProps } from "./types";

const { label, tone = "info" } = defineProps<BadgeProps>();
</script>

<template>
  <span :class="`badge badge-${tone}`">{{ label }}</span>
</template>
```

#svelte

<!-- prettier-ignore -->
```svelte [Badge.svelte]
<svelte:options runes={true} preserveWhitespace={false} />

<script lang="ts">
  import type { BadgeProps } from "./types";
  import type { ClassValue } from "svelte/elements";

  type Props = BadgeProps & { class?: ClassValue; style?: string };

  let { label, tone = "info", class: className, style, ...attributes }: Props = $props();

  /** The scope attributes of the styled parents that render this component, for its root. */
  function scopeAttributes(props: object): Record<string, ""> {
    const scope: Record<string, ""> = {};
    for (const name of Object.keys(props)) if (name.startsWith("data-uf-")) scope[name] = "";
    return scope;
  }
</script>

<span
  class={[`badge badge-${tone}`, className]}
  {style}
  {...scopeAttributes(attributes)}
>{label}</span>
```

#angular

<!-- prettier-ignore -->
```ts [badge.ts]
import type { BadgeProps } from "./types";
import {
  Component,
  Directive,
  ElementRef,
  type OnInit,
  Renderer2,
  inject,
  input,
} from "@angular/core";

/** The scope attributes taken off each host, for the roots its component renders later. */
const scopes = new WeakMap<Element, string[]>();

/**
 * Gives a root node of its component the scope attributes the component's styled parents put on
 * its host (ADR-0063), and takes them off the host, which keeps only `display: contents`.
 */
@Directive({ selector: "[ufScope]" })
export class ScopeAttributes implements OnInit {
  readonly ufScope = input.required<HTMLElement>();
  private readonly element = inject<ElementRef<Element>>(ElementRef);
  private readonly renderer = inject(Renderer2);

  ngOnInit(): void {
    const host = this.ufScope();
    let names = scopes.get(host);
    if (!names) {
      names = host.getAttributeNames().filter((name) => name.startsWith("data-uf-"));
      for (const name of names) this.renderer.removeAttribute(host, name);
      scopes.set(host, names);
    }
    for (const name of names) this.renderer.setAttribute(this.element.nativeElement, name, "");
  }
}

@Component({
  selector: "uf-badge",
  imports: [ScopeAttributes],
  host: { "[attr.class]": "null", "[attr.style]": "'display: contents;'" },
  preserveWhitespaces: false,
  template: `
    @let label = this.label();
    @let tone = this.tone();
    <span
      [class]="['badge badge-' + tone, this.class()].join(' ')"
      [style]="this.style()"
      [ufScope]="this.host"
    >{{ label }}</span>
  `,
})
export default class Badge {
  readonly label = input.required<BadgeProps["label"]>();
  readonly tone = input<Exclude<BadgeProps["tone"], undefined>, BadgeProps["tone"]>("info", {
    transform: (value) => (value === undefined ? "info" : value),
  });
  readonly class = input<string>();
  readonly style = input<Record<string, string | null | undefined>>();
  protected readonly host = inject<ElementRef<HTMLElement>>(ElementRef).nativeElement;
}
```

#solid

<!-- prettier-ignore -->
```tsx [Badge.tsx]
import type { BadgeProps } from "./types";
import { type JSX, mergeProps } from "solid-js";

export default function Badge(
  rawProps: BadgeProps & { class?: string; style?: JSX.CSSProperties },
) {
  const props = mergeProps({ tone: "info" } satisfies Partial<BadgeProps>, rawProps);
  return (
    <span
      class={cx(`badge badge-${props.tone}`, props.class)}
      style={props.style}
      {...scopeAttributes(props)}
    >
      {props.label}
    </span>
  );
}

/** Joins class names: strings as they are, and the names of an object's truthy entries. */
function cx(...parts: unknown[]): string {
  const names: string[] = [];
  for (const part of parts) {
    if (typeof part === "string") names.push(part);
    else if (part && typeof part === "object") {
      for (const [name, on] of Object.entries(part)) if (on) names.push(name);
    }
  }
  return names.join(" ");
}

/** The scope attributes of the styled parents that render this component, for its root. */
function scopeAttributes(props: object): Record<string, ""> {
  const scope: Record<string, ""> = {};
  for (const name of Object.keys(props)) if (name.startsWith("data-uf-")) scope[name] = "";
  return scope;
}
```

#qwik

<!-- prettier-ignore -->
```tsx [Badge.tsx]
import type { BadgeProps } from "./types";
import { type CSSProperties, type ClassList, component$ } from "@qwik.dev/core";

export default component$<BadgeProps & { class?: ClassList; style?: CSSProperties }>(
  ({ label, tone = "info", class: className, style, ...attributes }) => {
    return (
      <span
        class={[`badge badge-${tone}`, className]}
        {...scopeAttributes(attributes)}
        style={style}
      >
        {label}
      </span>
    );
  },
);

/** The scope attributes of the styled parents that render this component, for its root. */
function scopeAttributes(props: object): Record<string, ""> {
  const scope: Record<string, ""> = {};
  for (const key of Object.keys(props)) {
    if (key.startsWith("data-uf-")) scope[key] = "";
  }
  return scope;
}
```

#astro

<!-- prettier-ignore -->
```astro [Badge.astro]
---
import type { BadgeProps } from "./types";

interface Props extends BadgeProps {
  class?: string;
  style?: Record<string, string | number | undefined>;
}

const { label, tone = "info", class: className, style } = Astro.props;

/** The scope attributes of the styled parents that render this component, for its root. */
function scopeAttributes(props: object): Record<string, ""> {
  const scope: Record<string, ""> = {};
  for (const name of Object.keys(props)) if (name.startsWith("data-uf-")) scope[name] = "";
  return scope;
}
---

<span
  class:list={[`badge badge-${tone}`, className]}
  style={style}
  {...scopeAttributes(Astro.props)}
>{label}</span>
```

::

Each output tree also holds `types.ts`, copied unchanged, so every output checks and loads on its own. Angular declares each input on its own, typed through the interface: `BadgeProps["label"]`.

A type can come from a child's module too. Here a form's prop is typed with the props its child exports:

<!-- prettier-ignore -->
```tsx [Form.uf.tsx]
import Field from "./Field.uf.tsx";
import type { FieldProps } from "./Field.uf.tsx";

// A props type a child's module exports, imported from the child (ADR-0067).
export default function Form({ field }: { field: FieldProps }) {
  return (
    <form aria-label="Sign up">
      <Field name={field.name} label={field.label} />
    </form>
  );
}
```

And from a package, through its `types` and `exports`, as TypeScript's bundler resolution finds them. `value` and `interval` come from rxjs's generic `TimeInterval<T>`, and `label` from a local module:

<!-- prettier-ignore -->
```tsx [Status.uf.tsx]
import type { TimeInterval } from "rxjs";

import type { Labelled } from "./types";

// Members a package declares, `value` and `interval` from rxjs's generic `TimeInterval<T>`, beside
// one a `.ts` module declares.
type StatusProps = TimeInterval<string> & Labelled;

export default function Status({ value, interval, label }: StatusProps) {
  return (
    <p>
      {label}: {value} after {interval} ms
    </p>
  );
}
```

## What the compiler reads

The compiler reads a props type as written, without running a type checker, so the same source always gives the same props. It follows:

- interfaces and type aliases, local or imported, and their re-exports;
- `extends` chains, across modules (`types/extends-chain`);
- intersections of interfaces and type literals (`types/intersection-props`);
- unions and literal unions;
- generic declarations, instantiated with their arguments;
- the five utility types: `Partial`, `Required`, `Pick`, `Omit` and `Readonly`.

For example, the props of a text field can pick what they require from a looser interface:

<!-- prettier-ignore -->
```ts [types.ts]
// Every option of a field is optional: the component's props pick the ones it requires.
export interface FieldOptions {
  name?: string;
  label?: string;
  placeholder?: string;
  required?: boolean;
}
```

<!-- prettier-ignore -->
```tsx [TextField.uf.tsx]
import type { FieldOptions } from "./types";

// The five utility types of plan §5.5, over an imported interface.
export type TextFieldProps = Required<Pick<FieldOptions, "name" | "label">> &
  Readonly<Partial<Omit<FieldOptions, "name" | "label">>>;

export default function TextField({ name, label, placeholder, required }: TextFieldProps) {
  return (
    <label>
      {label}
      <input name={name} placeholder={placeholder} required={required} />
    </label>
  );
}
```

`name` and `label` are required, and `placeholder` and `required` optional and read-only. Vue's compiler resolves that alias by itself, so Vue's output keeps it as written:

<!-- prettier-ignore -->
```vue [TextField.vue]
<script setup lang="ts">
import type { FieldOptions } from "./types";

export type TextFieldProps = Required<Pick<FieldOptions, "name" | "label">> &
  Readonly<Partial<Omit<FieldOptions, "name" | "label">>>;

const {
  name,
  label,
  placeholder = undefined,
  required = undefined,
} = defineProps<TextFieldProps>();
</script>

<template>
  <label>{{ label }}<input :name="name" :placeholder="placeholder" :required="required" /></label>
</template>
```

Where Vue's compiler can't resolve a construct, such as a type from a package, Vue's output prints one member for each prop, each typed through the original:

<!-- prettier-ignore -->
```vue [Status.vue]
<script setup lang="ts">
import type { Labelled } from "./types";
import type { TimeInterval } from "rxjs";

type StatusProps = TimeInterval<string> & Labelled;

const { value, interval, label } = defineProps<{
  value: StatusProps["value"];
  interval: StatusProps["interval"];
  label: StatusProps["label"];
}>();
</script>

<template>
  <p>{{ label }}: {{ value }} after {{ interval }} ms</p>
</template>
```

Every other output keeps `StatusProps` and imports what it names.

### What stays out

A props type the compiler can't read for every framework is a diagnostic at its span, never a guess:

- [UF6001](/docs/reference/diagnostics#UF6001): the type names a declaration the compiler can't find, such as a typo, a missing file or a package without types.
- [UF6002](/docs/reference/diagnostics#UF6002): conditional and mapped types, `infer`, `keyof`, `typeof` and template-literal types, which need a type checker.
- [UF6003](/docs/reference/diagnostics#UF6003): the type is declared in another module without `export`, so no output can import it.
- [UF6004](/docs/reference/diagnostics#UF6004): the props type isn't an object type, such as a union of two object types.
- [UF6005](/docs/reference/diagnostics#UF6005): an intersection or an `extends` chain declares one prop twice, with two types.

For UF6002, `compile()` takes a second type oracle, `createTsgoOracle({ root })` from `@unframework.dev/type-oracle-tsgo`, which hands those constructs to TypeScript's own checker. The Vite plugin always uses the default one.

## Generic components

A list, a select or a table is often generic over its items. Declare the type parameter on the component's function, and let its props take it:

<!-- prettier-ignore -->
```tsx [List.uf.tsx]
// A component generic over its items (ADR-0068): `T` is what its consumer's `items` holds.
export interface ListProps<T> {
  label: string;
  items: T[];
  selected?: T;
}

export default function List<T>({ label, items, selected }: ListProps<T>) {
  return (
    <ul aria-label={label}>
      {items.map((item, index) => (
        <li key={index} aria-current={item === selected ? "true" : undefined}>
          {String(item)}
        </li>
      ))}
    </ul>
  );
}
```

A consumer never names `T`: it comes from the `items` they pass, so `selected` must be one of them. Each framework writes it in its own generic form:

::framework-switcher

#react

<!-- prettier-ignore -->
```tsx [List.tsx]
import type { CSSProperties } from "react";

export interface ListProps<T> {
  label: string;
  items: T[];
  selected?: T;
}

export interface ListAttributes {
  className?: string;
  style?: CSSProperties;
}

export default function List<T>({
  label,
  items,
  selected,
  className,
  style,
  ...attributes
}: ListProps<T> & ListAttributes) {
  return (
    <ul aria-label={label} className={className} style={style} {...scopeAttributes(attributes)}>
      {items.map((item, index) => (
        <li key={index} aria-current={item === selected ? "true" : undefined}>
          {String(item)}
        </li>
      ))}
    </ul>
  );
}

/** The scope attributes of the styled parents that render this component, for its root. */
function scopeAttributes(props: object): Record<string, ""> {
  const scope: Record<string, ""> = {};
  for (const key of Object.keys(props)) {
    if (key.startsWith("data-uf-")) scope[key] = "";
  }
  return scope;
}
```

#vue

<!-- prettier-ignore -->
```vue [List.vue]
<script setup lang="ts" generic="T">
export interface ListProps<T> {
  label: string;
  items: T[];
  selected?: T;
}

const { label, items, selected = undefined } = defineProps<ListProps<T>>();
</script>

<template>
  <ul :aria-label="label">
    <li
      v-for="(item, index) in items"
      :key="index"
      :aria-current="item === selected ? 'true' : undefined"
    >{{ String(item) }}</li>
  </ul>
</template>
```

#svelte

<!-- prettier-ignore -->
```svelte [List.svelte]
<svelte:options runes={true} preserveWhitespace={false} />

<script lang="ts" module>
  export interface ListProps<T> {
    label: string;
    items: T[];
    selected?: T;
  }
</script>

<script lang="ts" generics="T">
  import type { ClassValue } from "svelte/elements";

  type Props = ListProps<T> & { class?: ClassValue; style?: string };

  let { label, items, selected, class: className, style, ...attributes }: Props = $props();

  /** The scope attributes of the styled parents that render this component, for its root. */
  function scopeAttributes(props: object): Record<string, ""> {
    const scope: Record<string, ""> = {};
    for (const name of Object.keys(props)) if (name.startsWith("data-uf-")) scope[name] = "";
    return scope;
  }
</script>

<ul aria-label={label} class={className} {style} {...scopeAttributes(attributes)}>
  {#each items as item, index (index)}
    <li aria-current={item === selected ? "true" : undefined}>{String(item)}</li>
  {/each}
</ul>
```

#angular

<!-- prettier-ignore -->
```ts [list.ts]
import {
  Component,
  Directive,
  ElementRef,
  type OnInit,
  Renderer2,
  inject,
  input,
} from "@angular/core";

export interface ListProps<T> {
  label: string;
  items: T[];
  selected?: T;
}

/** The scope attributes taken off each host, for the roots its component renders later. */
const scopes = new WeakMap<Element, string[]>();

/**
 * Gives a root node of its component the scope attributes the component's styled parents put on
 * its host (ADR-0063), and takes them off the host, which keeps only `display: contents`.
 */
@Directive({ selector: "[ufScope]" })
export class ScopeAttributes implements OnInit {
  readonly ufScope = input.required<HTMLElement>();
  private readonly element = inject<ElementRef<Element>>(ElementRef);
  private readonly renderer = inject(Renderer2);

  ngOnInit(): void {
    const host = this.ufScope();
    let names = scopes.get(host);
    if (!names) {
      names = host.getAttributeNames().filter((name) => name.startsWith("data-uf-"));
      for (const name of names) this.renderer.removeAttribute(host, name);
      scopes.set(host, names);
    }
    for (const name of names) this.renderer.setAttribute(this.element.nativeElement, name, "");
  }
}

@Component({
  selector: "uf-list",
  imports: [ScopeAttributes],
  host: { "[attr.class]": "null", "[attr.style]": "'display: contents;'" },
  preserveWhitespaces: false,
  template: `
    @let label = this.label();
    @let items = this.items();
    @let selected = this.selected();
    <ul
      [attr.aria-label]="label"
      [class]="this.class()"
      [style]="this.style()"
      [ufScope]="this.host"
    >
      @for (item of items; track index; let index = $index) {
        <li [attr.aria-current]="item === selected ? 'true' : undefined">{{ String(item) }}</li>
      }
    </ul>
  `,
})
export default class List<T> {
  readonly label = input.required<string>();
  readonly items = input.required<T[]>();
  readonly selected = input<T>();
  readonly class = input<string>();
  readonly style = input<Record<string, string | null | undefined>>();
  protected readonly String = String;
  protected readonly host = inject<ElementRef<HTMLElement>>(ElementRef).nativeElement;
}
```

#solid

<!-- prettier-ignore -->
```tsx [List.tsx]
import { For, type JSX, createMemo, untrack } from "solid-js";

export interface ListProps<T> {
  label: string;
  items: T[];
  selected?: T;
}

export default function List<T>(
  props: ListProps<T> & { class?: string; style?: JSX.CSSProperties },
) {
  return (
    <ul
      aria-label={props.label}
      class={props.class}
      style={props.style}
      {...scopeAttributes(props)}
    >
      <KeyedFor each={props.items} by={(item, index) => index}>
        {(item) => (
          <li aria-current={item.value === props.selected ? "true" : undefined}>
            {String(item.value)}
          </li>
        )}
      </KeyedFor>
    </ul>
  );
}

/** The scope attributes of the styled parents that render this component, for its root. */
function scopeAttributes(props: object): Record<string, ""> {
  const scope: Record<string, ""> = {};
  for (const name of Object.keys(props)) if (name.startsWith("data-uf-")) scope[name] = "";
  return scope;
}

/** A list whose rows follow their keys, so a row keeps its element while the list reorders and while its item is replaced. */
function KeyedFor<T>(props: {
  each: readonly T[];
  by: (item: T, index: number) => unknown;
  children: (row: { readonly value: T; readonly index: number }) => JSX.Element;
}): JSX.Element {
  const items = createMemo(() => {
    const rows = new Map<unknown, T>();
    props.each.forEach((item, index) => {
      const key = props.by(item, index);
      rows.set(rows.has(key) ? {} : key, item);
    });
    return rows;
  });
  return (
    <For each={[...items().keys()]}>
      {(key, index) => {
        const item = createMemo(() => items().get(key) as T);
        return untrack(() =>
          props.children({
            get value() {
              return item();
            },
            get index() {
              return index();
            },
          }),
        );
      }}
    </For>
  );
}
```

#qwik

<!-- prettier-ignore -->
```tsx [List.tsx]
import { type CSSProperties, type ClassList, component$ } from "@qwik.dev/core";

export interface ListProps<T> {
  label: string;
  items: T[];
  selected?: T;
}

export default component$(
  <T,>({
    label,
    items,
    selected,
    class: className,
    style,
    ...attributes
  }: ListProps<T> & { class?: ClassList; style?: CSSProperties }) => {
    return (
      <ul aria-label={label} {...scopeAttributes(attributes)} class={className} style={style}>
        {items.map((item, index) => (
          <li key={index} aria-current={item === selected ? "true" : undefined}>
            {String(item)}
          </li>
        ))}
      </ul>
    );
  },
);

/** The scope attributes of the styled parents that render this component, for its root. */
function scopeAttributes(props: object): Record<string, ""> {
  const scope: Record<string, ""> = {};
  for (const key of Object.keys(props)) {
    if (key.startsWith("data-uf-")) scope[key] = "";
  }
  return scope;
}
```

#astro

<!-- prettier-ignore -->
```astro [List.astro]
---
export interface ListProps<T> {
  label: string;
  items: T[];
  selected?: T;
}

interface Props<T> extends ListProps<T> {
  class?: string;
  style?: Record<string, string | number | undefined>;
}

const { label, items, selected, class: className, style } = Astro.props;

/** The scope attributes of the styled parents that render this component, for its root. */
function scopeAttributes(props: object): Record<string, ""> {
  const scope: Record<string, ""> = {};
  for (const name of Object.keys(props)) if (name.startsWith("data-uf-")) scope[name] = "";
  return scope;
}
---

<ul aria-label={label} class:list={[className]} style={style} {...scopeAttributes(Astro.props)}>
  {items.map((item) => (
    <li aria-current={item === selected ? "true" : undefined}>{String(item)}</li>
  ))}
</ul>
```

::

| Target       | Generic form                                                      |
| ------------ | ----------------------------------------------------------------- |
| React, Solid | a generic function component                                      |
| Vue          | `<script setup lang="ts" generic="T">`                            |
| Svelte       | `<script lang="ts" generics="T">`                                 |
| Angular      | a generic component class, whose `T` Angular infers from inputs   |
| Qwik         | a generic arrow inside `component$`, `<T,>(…) => …`, with no cast |
| Astro        | `interface Props<T>`                                              |

A type parameter can take a constraint, `function Table<T extends { id: string; label: string }>` (`generics/constrained`). Explicit type arguments on a tag, `<List<string> … />`, are [UF6006](/docs/reference/diagnostics#UF6006), and so is a generic component as a candidate of `<component is>`, since several frameworks' templates have no form for them.

### Scoped slots on Angular

A scoped slot's props can name the type parameter too, so a consumer's fill reads their own item type:

<!-- prettier-ignore -->
```tsx [Picker.uf.tsx]
import { defineSlots } from "@uxfront/unframework";
import type { Element } from "@uxfront/unframework";

// A scoped slot whose props name the type parameter (ADR-0068): a consumer's fill reads `T`.
export interface PickerProps<T> {
  items: T[];
}

export default function Picker<T>({ items }: PickerProps<T>) {
  const slots = defineSlots<{ item?(props: { item: T }): Element }>();
  return (
    <ul>
      {items.map((item, index) => (
        <li key={index}>{slots.item?.({ item })}</li>
      ))}
    </ul>
  );
}
```

React, Vue, Svelte, Solid, Qwik and Astro type the fill's `item` by the type argument the consumer's `items` give. Angular infers a component's type parameter from its inputs alone, and a slot's directive can't infer it, so the slot's context takes the parameter's constraint, and an unconstrained `T` reads as `any`:

<!-- prettier-ignore -->
```ts [picker.ts]
export type PickerItemContext = { item: any };
```

The component renders the same. Only a consumer's type checking differs, so the compiler says so for information, with [UF4004](/docs/reference/diagnostics#UF4004) at the slot (`generic-slot-props` on the [targets page](/docs/reference/targets#capabilities)). Give `T` a constraint that names what consumers read, or accept the looser type on Angular.

## Exported types

Every type a component's module exports, each output exports under the same name: its props type, a type the props reach, and one that no component uses at all:

<!-- prettier-ignore -->
```tsx [Button.uf.tsx]
// Every type the module exports is exported by each output (ADR-0068): one the props reach, and
// one no component reaches.
export type ButtonTone = "primary" | "secondary";

export type ButtonSize = "small" | "large";

export interface ButtonProps {
  label: string;
  tone?: ButtonTone;
}

export default function Button({ label, tone = "primary" }: ButtonProps) {
  return (
    <button type="button" class={`button button-${tone}`}>
      {label}
    </button>
  );
}
```

React, Solid, Qwik and Angular export them from the module, Vue from `<script setup>`, Astro from its frontmatter, and Svelte from `<script module>`:

<!-- prettier-ignore -->
```svelte [Button.svelte]
<svelte:options runes={true} preserveWhitespace={false} />

<script lang="ts" module>
  export type ButtonTone = "primary" | "secondary";

  export type ButtonSize = "small" | "large";

  export interface ButtonProps {
    label: string;
    tone?: ButtonTone;
  }
</script>

<script lang="ts">
  import type { ClassValue } from "svelte/elements";

  type Props = ButtonProps & { class?: ClassValue; style?: string };

  let { label, tone = "primary", class: className, style, ...attributes }: Props = $props();

  /** The scope attributes of the styled parents that render this component, for its root. */
  function scopeAttributes(props: object): Record<string, ""> {
    const scope: Record<string, ""> = {};
    for (const name of Object.keys(props)) if (name.startsWith("data-uf-")) scope[name] = "";
    return scope;
  }
</script>

<button
  type="button"
  class={[`button button-${tone}`, className]}
  {style}
  {...scopeAttributes(attributes)}
>{label}</button>
```

So a consumer imports them as they would from any component written in their framework, and their checker reports a misuse. The tests type-check a consumer in each framework, like this React one, which must fail at the two lines its comments name:

<!-- prettier-ignore -->
```tsx [MisuseType.tsx]
import Button, {
  type ButtonProps,
  type ButtonSize,
} from "../../../../../integration/cases/types/exported-types/__output__/react/Button";

export function MisuseType() {
  // @uf-expect TS2322 Button.type:ButtonProps
  const props: ButtonProps = { label: "Save", tone: "danger" };
  // @uf-expect TS2322 Button.type:ButtonSize
  const size: ButtonSize = "huge";
  return <Button label={props.label} data-size={size} />;
}
```

A module can re-export a type it imports, so its consumers find it beside the component:

<!-- prettier-ignore -->
```tsx [Palette.uf.tsx]
import Swatch from "./Swatch.uf.tsx";
import type { Tone } from "./types";

// Consumers of `Palette` import the shared type from it.
export type { Tone } from "./types";

export default function Palette({ tone }: { tone: Tone }) {
  return (
    <div class="palette">
      <Swatch tone={tone} />
    </div>
  );
}
```

To read a component's full props, attributes included, use the framework's own utility:

| Target               | Its props                                           |
| -------------------- | --------------------------------------------------- |
| React, Solid, Svelte | `ComponentProps<typeof Button>`                     |
| Vue                  | `InstanceType<typeof Button>["$props"]`             |
| Qwik                 | `PropsOf<typeof Button>`                            |
| Astro                | `ComponentProps<typeof Button>`, from `astro/types` |

Angular has no such utility for a component's inputs, so an Angular consumer imports the exported props type, `ButtonProps`, instead.

The `…Events`, `…Models` and `…Slots` interfaces that an output exports beside its component, such as `FieldEvents` on [Child components](/docs/components/child-components), stay as they are.

The decisions behind this page are [ADR-0067](https://github.com/uxfront-com/unframework/blob/main/docs/adrs/0067-the-type-oracle-and-cross-file-props-types.md) and [ADR-0068](https://github.com/uxfront-com/unframework/blob/main/docs/adrs/0068-generic-components-and-exported-public-types.md). Values shared between components, rather than types, are on [Shared modules](/docs/components/shared-modules).
