forked from thousandyears/Lexicon
-
Notifications
You must be signed in to change notification settings - Fork 0
Language TypeScript
Oliver Atkinson edited this page May 31, 2026
·
1 revision
The TypeScript generator emits a stand-alone .ts file.
swift run lexicon-generate commerce.lexicon --type ts -o src/generated/commerce-lexiconThis writes:
src/generated/commerce-lexicon.ts
Import it from application code:
import { commerce } from "./generated/commerce-lexicon";
const submit = commerce.api.order.submit;
console.log(submit.__);The __ getter returns the exact lemma ID.
Generated TypeScript defines:
-
I, the shared marker interface. -
L, the base class that stores the exact ID. - one class per concrete lemma.
- one interface per semantic type.
- class fields for own children.
- inherited fields where a type provides children.
Example:
const button = commerce.ui.checkout.button.primary;
sendAnalytics({
event: commerce.analytics.event.checkout_started.__,
target: button.__,
});Synonyms resolve to the generated source member:
const enabled = commerce.ui.product.card.buy.enabled;
const active = commerce.ui.product.card.buy.active;
console.assert(enabled.__ === active.__);Use this when a UI term and analytics term need to preserve their local vocabulary but represent one concept.
{
"scripts": {
"generate:lexicon": "swift run lexicon-generate lexicons/commerce.lexicon --type ts -o src/generated/commerce-lexicon",
"typecheck": "npm run generate:lexicon && tsc --noEmit"
}
}If TypeScript builds should not require Swift, generate and commit the .ts file.
Generated TypeScript gives you stable identifiers and typed navigation. It does not validate runtime JSON payloads by itself.
Pair it with your existing schema tool when crossing network or persistence boundaries:
const key = commerce.api.order.submit.__;
const payload = SubmitOrderSchema.parse(input);Use Lexicon for vocabulary identity and relationships. Use validation libraries for data shape and runtime type safety.