Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 30 additions & 10 deletions packages/types/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,12 @@ Backend integration:
Types don't assume any specific backend:

```typescript
interface DataSource<T = any> {
import type { DataSource, QueryParams, QueryResult } from '@object-ui/types';

// Two methods quoted from the shipped `DataSource`. `extends Pick` ties the
// quotation to the real interface: the day either member is renamed away or its
// return type changes, this block stops compiling.
interface DataSourceExcerpt<T = any> extends Pick<DataSource<T>, 'find' | 'create'> {
find(resource: string, params?: QueryParams): Promise<QueryResult<T>>;
create(resource: string, data: Partial<T>): Promise<T>;
// Works with REST, GraphQL, ObjectQL, or anything
Expand All @@ -229,6 +234,8 @@ interface DataSource<T = any> {
All components support `className` for Tailwind styling:

```typescript
import type { ButtonSchema } from '@object-ui/types';

const button: ButtonSchema = {
type: 'button',
label: 'Click Me',
Expand All @@ -241,11 +248,13 @@ const button: ButtonSchema = {
Full TypeScript support with discriminated unions:

```typescript
type AnySchema =
| InputSchema
| ButtonSchema
| FormSchema
| /* 50+ more */;
import type { AnySchema, ButtonSchema, FormSchema, InputSchema } from '@object-ui/types';

// The shipped `AnySchema` carries 50+ members. These three are a slice of it,
// and the assignment below is what proves the slice really is part of the union.
type SchemaSlice = InputSchema | ButtonSchema | FormSchema;
declare const slice: SchemaSlice;
const anySchema: AnySchema = slice;

function render(schema: AnySchema) {
switch (schema.type) {
Expand All @@ -260,6 +269,20 @@ function render(schema: AnySchema) {
Components can nest indefinitely:

```typescript
import type { ContainerSchema, FlexSchema, SidebarSchema } from '@object-ui/types';

// The two leaves are annotated so the nesting below is checked against the
// shipped types rather than absorbed by `BaseSchema`'s index signature.
const sidebar: SidebarSchema = {
type: 'sidebar',
nav: [{ label: 'Home', href: '/' }]
};

const main: ContainerSchema = {
type: 'container',
children: [{ type: 'data-table', data: [] }]
};

const page: FlexSchema = {
type: 'flex',
direction: 'col',
Expand All @@ -268,10 +291,7 @@ const page: FlexSchema = {
{
type: 'flex',
direction: 'row',
children: [
{ type: 'sidebar', nav: [...] },
{ type: 'container', children: [...] }
]
children: [sidebar, main]
}
]
};
Expand Down
2 changes: 0 additions & 2 deletions scripts/check-doc-snippet-types.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -741,8 +741,6 @@ const UNGATED_DOCS = {
'7 undefined-name diagnostic(s) — blocks continue an earlier block, or use ambient names the page never defines; plus TS2741x1 — candidate real defects, un-triaged',
'packages/react-runtime/README.md':
'25 undefined-name diagnostic(s) — blocks continue an earlier block, or use ambient names the page never defines; plus TS2813x1 TS2814x1 — candidate real defects, un-triaged',
'packages/types/README.md':
'3 parse diagnostic(s) — blocks fenced `ts` that are bare object literals or elided bodies; 3 undefined-name diagnostic(s) — blocks continue an earlier block, or use ambient names the page never defines',
};

// ── Fence scanning ───────────────────────────────────────────────────────────
Expand Down
Loading