···
Note that `Caption` won't exist as a separate def—the abstraction is erased in the output.
+
TypeSpec scalars let you create named types with constraints. **By default, scalars create standalone defs** (like models):
+
import "@typelex/emitter";
+
namespace com.example {
+
scalar Handle extends string;
+
scalar Bio extends string;
+
This creates three defs: `main`, `handle`, and `bio`:
+
"handle": { "type": "ref", "ref": "#handle" },
+
"bio": { "type": "ref", "ref": "#bio" }
+
Use `@inline` to expand a scalar inline instead:
+
import "@typelex/emitter";
+
namespace com.example {
+
scalar Handle extends string;
+
Now `Handle` is expanded inline (no separate def):
+
"handle": { "type": "string", "maxLength": 50 }
## Top-Level Lexicon Types
TypeSpec uses `model` for almost everything. Decorators specify what kind of Lexicon type it becomes.
···
## Defaults and Constants
+
You can set default values on properties:
import "@typelex/emitter";
···
Maps to: `{"default": 1}`, `{"default": "en"}`
+
You can also set defaults on scalar and union types using the `@default` decorator:
+
import "@typelex/emitter";
+
namespace com.example {
+
scalar Mode extends string;
+
union Priority { 1, 2, 3 }
+
This creates a default on the type definition itself:
+
For unions with token references, pass the model directly:
+
import "@typelex/emitter";
+
namespace com.example {
+
union EventType { Hybrid, InPerson, Virtual, string }
+
@token model InPerson {}
+
@token model Virtual {}
+
This resolves to the fully-qualified token NSID:
+
"com.example#inPerson",
+
"default": "com.example#inPerson"
+
**Important:** When a scalar or union creates a standalone def (not `@inline`), property-level defaults must match the type's `@default`. Otherwise you'll get an error:
+
scalar Mode extends string;
+
mode?: Mode = "custom"; // ERROR: Conflicting defaults!
+
1. Make the defaults match: `mode?: Mode = "standard"`
+
2. Mark the type `@inline`: Allows property-level defaults
+
3. Remove the property default: Uses the type's default
Use `@readOnly` with a default: