You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
fix(typegen): derive interface names from slug, not label (#1349)
* fix(typegen): derive interface names from slug, not label
Generated TS interface names in emdash-env.d.ts were derived from the
collection's human label (labelSingular). Labels are arbitrary and
user-controlled, so a label with spaces/punctuation produced an invalid
identifier (e.g. `Book (do not use)` -> `Book(donotuse)`) and two
collections sharing a label collapsed to a duplicate identifier -- both
rejected by astro check/tsc. Derive names from the slug instead, which is
constrained to /^[a-z][a-z0-9_]*$/ and unique, so PascalCasing it always
yields a valid, collision-free identifier.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
* fix(typegen): address review — mark breaking, correct JSDoc
- Changeset bumped patch -> minor and rewritten to call out the
interface-name rename (e.g. Page -> Pages) as breaking, per AGENTS.md.
- Drop the inaccurate "collision-free" guarantee from getInterfaceName
JSDoc: test_1 and test1 both PascalCase to Test1.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
* fix(typegen): singularize slug-derived interface names
Review feedback: an interface describes a single entry, not the
collection, so the name should be singular -- `Post`, not `Posts`.
Keep deriving from the slug (valid, constrained identifier) but
singularize it first.
Singularization can map two distinct slugs onto the same name
(`book` and `books` both -> `Book`), which would reintroduce the
duplicate-identifier error this PR fixes, so resolve collisions in
generateTypesFile with a deterministic numeric suffix.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
* fix(typegen): dedupe interface names against emitted set; apply in CLI export
Address review on #1349:
- uniqueInterfaceNames now picks suffixes against the set of names
already emitted rather than a per-base counter, so a suffixed name
can't collide with another slug's base name (slugs book/books/book2
no longer emit Book2 twice).
- The schema export route (?format=typescript) now resolves names via
uniqueInterfaceNames before generating, so `emdash types` on a project
with colliding singularized slugs no longer emits duplicate interfaces.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
---------
Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
**Breaking:** generated TypeScript interface names in `emdash-env.d.ts` now derive from the collection **slug** (singularized) instead of `labelSingular`. This fixes invalid identifiers (labels with spaces/punctuation) and duplicate identifiers (two collections sharing a label), while keeping names singular so each interface reads as a single entry (slug `posts` → `Post`, `blog_posts` → `BlogPost`). Interfaces are renamed wherever the old label-derived name differed from the slug. Users should regenerate `emdash-env.d.ts` (`emdash types` or dev-server start) and update any direct interface references in their code.
0 commit comments