An experimental TypeSpec syntax for Lexicon

document @external

+25 -5
+25 -5
DOCS.md
··· 236 236 237 237 This works across files too—just remember to `import` the file with the definition. 238 238 239 - ### External Stubs 239 + ### External References 240 240 241 - If you don't have TypeSpec definitions for external Lexicons, you can stub them out: 241 + If you don't have TypeSpec definitions for external Lexicons, you can stub them out using the `@external` decorator: 242 242 243 243 ```typescript 244 244 import "@typelex/emitter"; ··· 249 249 } 250 250 } 251 251 252 - // Empty stub (like .d.ts in TypeScript) 252 + // External stub (like .d.ts in TypeScript) 253 + @external 253 254 namespace com.atproto.label.defs { 254 255 model SelfLabels { } 255 256 } 256 257 ``` 257 258 258 - You could collect stubs in one file and import them: 259 + The `@external` decorator tells the emitter to skip JSON output for that namespace. This is useful when referencing definitions from other Lexicons that you don't want to re-emit. 260 + 261 + You could collect external stubs in one file and import them: 259 262 260 263 ```typescript 261 264 import "@typelex/emitter"; ··· 268 271 } 269 272 ``` 270 273 271 - You'll want to replace the stubbed lexicons in the output folder with their real JSON before running codegen. 274 + Then in `atproto-stubs.tsp`: 275 + 276 + ```typescript 277 + import "@typelex/emitter"; 278 + 279 + @external 280 + namespace com.atproto.label.defs { 281 + model SelfLabels { } 282 + } 283 + 284 + @external 285 + namespace com.atproto.repo.defs { 286 + model StrongRef { } 287 + } 288 + // ... more stubs 289 + ``` 290 + 291 + You'll want to ensure the real JSON for external Lexicons is available before running codegen. 272 292 273 293 ### Inline Models 274 294