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
emdash-env.d.ts already extends EmDashCollections, so getEmDashCollection("posts") returns typed data. The name parameter, though, is T extends string:
This means editors don't suggest the registered collection names. A typo such as getEmDashCollection("post") still compiles, and data falls back to Record<string, unknown>. The type error then appears where a field is used, not at the misspelled collection name.
Proposal
Change the constraint so registered names show up as completions while any string is still accepted:
CollectionName is always a string, so the internal helpers and InferCollectionData stay as they are. This change adds autocomplete only. Typos still compile.
I have this working on a branch:
pnpm build, pnpm typecheck and pnpm typecheck:demos pass.
I tested it against a mock EmDashCollections with posts and pages:
Completions inside getEmDashCollection("") list posts and pages.
"posts" still resolves to the posts data type.
getEmDashEntry("pages", ...) resolves to the pages data type.
Unknown literals and plain string variables still compile.
Questions
The constraint changes from string to CollectionName but accepts the same values. Typechecks in the repo pass, including core calls that pass a string variable or an explicit <string, T>. Is there code outside the repo, such as tooling or plugins, that could depend on the old constraint?
Should the other public helpers that take a collection name accept CollectionName too? These are getTermsForEntries, getAllTermsForEntries, getEntryTerms, getEntriesByTerm, getTranslations and getCommentCount. The only gain would be autocomplete on the collection argument.
Would typed taxonomy names be welcome as a follow-up? That means the "tag" in getTerm("tag", slug) and getTermsForEntries(..., "tag"). There's no registry for taxonomies yet, so it would need:
A new EmDashTaxonomies interface.
generateTypesFile to accept and emit taxonomy definitions.
Dev typegen, the typegen route and emdash types to pass them in.
Taxonomies included in the schema hash, so adding one regenerates emdash-env.d.ts.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
The problem
emdash-env.d.tsalready extendsEmDashCollections, sogetEmDashCollection("posts")returns typeddata. The name parameter, though, isT extends string:This means editors don't suggest the registered collection names. A typo such as
getEmDashCollection("post")still compiles, anddatafalls back toRecord<string, unknown>. The type error then appears where a field is used, not at the misspelled collection name.Proposal
Change the constraint so registered names show up as completions while any string is still accepted:
CollectionNameis always a string, so the internal helpers andInferCollectionDatastay as they are. This change adds autocomplete only. Typos still compile.I have this working on a branch:
pnpm build,pnpm typecheckandpnpm typecheck:demospass.EmDashCollectionswithpostsandpages:getEmDashCollection("")listpostsandpages."posts"still resolves to thepostsdata type.getEmDashEntry("pages", ...)resolves to thepagesdata type.stringvariables still compile.Questions
The constraint changes from
stringtoCollectionNamebut accepts the same values. Typechecks in the repo pass, including core calls that pass astringvariable or an explicit<string, T>. Is there code outside the repo, such as tooling or plugins, that could depend on the old constraint?Should the other public helpers that take a collection name accept
CollectionNametoo? These aregetTermsForEntries,getAllTermsForEntries,getEntryTerms,getEntriesByTerm,getTranslationsandgetCommentCount. The only gain would be autocomplete on the collection argument.Would typed taxonomy names be welcome as a follow-up? That means the
"tag"ingetTerm("tag", slug)andgetTermsForEntries(..., "tag"). There's no registry for taxonomies yet, so it would need:EmDashTaxonomiesinterface.generateTypesFileto accept and emit taxonomy definitions.emdash typesto pass them in.emdash-env.d.ts.All reactions