Skip to content

docs: add a playground sample to the config schema - #899

Merged
dsherret merged 2 commits into
mainfrom
schema-playground-sample
Nov 5, 2026
Merged

dsherret merged 2 commits into
mainfrom
schema-playground-sample

Conversation

@dsherret

@dsherret dsherret commented Nov 5, 2026 •

Copy link
Copy Markdown
Member

Adds an x-playground sample to the config schema, which the dprint.dev playground puts in the editor when it opens this plugin (dprint/dprint#1442) so there's code to format right away.

The sample isn't formatted, and formats to:

import { Component, type Props } from "./component.ts";

export interface User {
  id: number;
  name: string;
  email?: string;
}

const users: User[] = [
  { id: 1, name: "Alice" },
  { id: 2, name: "Bob", email: "bob@example.com" },
];

export class UserList extends Component<Props> {
  private readonly items = new Map<number, User>();
  constructor(props: Props) {
    super(props);
    for (const user of users) this.items.set(user.id, user);
  }
  find(predicate: (user: User) => boolean): User | undefined {
    return [...this.items.values()].find(predicate);
  }
}

const names = users.filter(u => u.email != null).map(u => u.name.toUpperCase());
console.log(`found ${names.length} users`, names);

This also updates CI to @dprint/automation 0.14.3, whose publish-schema checks that the sample formats and sets its extension to ts (dprint/automation#15).

@dsherret dsherret changed the title feat: add a playground sample to the config schema docs: add a playground sample to the config schema Nov 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant