An experimental TypeSpec syntax for Lexicon
56
fork

Configure Feed

Select the types of activity you want to include in your feed.

twk

+27 -8
+27 -8
packages/emitter/src/emitter.ts
··· 421 421 message: `Union has no variants. Atproto unions must contain either model references or string literals.`, 422 422 target: unionType, 423 423 }); 424 + return null; 424 425 } 425 426 426 - return null; 427 + // Case 4: Invalid string literal union (has literals but no string type) 428 + if (variants.stringLiterals.length > 0 && !variants.hasStringType) { 429 + throw new Error( 430 + 'String literal unions must include "| string" to allow unknown values', 431 + ); 432 + } 433 + 434 + // Unexpected case 435 + throw new Error( 436 + "Unexpected union type - neither string enum nor model refs nor empty", 437 + ); 427 438 } 428 439 429 440 private parseUnionVariants(unionType: Union) { ··· 830 841 return this.addDescription({ type: "unknown" }, propDesc); 831 842 default: 832 843 // Unhandled type kind 833 - return null; 844 + throw new Error( 845 + `TODO: Unhandled type kind "${type.kind}" in typeToLexiconDefinition`, 846 + ); 834 847 } 835 848 } 836 849 ··· 874 887 return unionDef; 875 888 } 876 889 } 877 - // TODO: Handle Closed<> with non-union argument 878 - return null; 890 + throw new Error( 891 + "Closed<> template argument must be a union of model references", 892 + ); 879 893 } 880 894 881 895 // 3. Check for model reference (named models from other namespaces) ··· 888 902 if (isArrayModelType(this.program, model)) { 889 903 const arrayDef = this.modelToLexiconArray(model, prop); 890 904 if (!arrayDef) { 891 - // TODO: Handle array conversion failure 892 - return null; 905 + throw new Error( 906 + "Array type conversion failed - array must have a valid item type", 907 + ); 893 908 } 894 909 return this.addDescription(arrayDef, propDesc); 895 910 } ··· 1078 1093 1079 1094 if (itemType && isType(itemType)) { 1080 1095 const itemDef = this.typeToLexiconDefinition(itemType); 1081 - if (!itemDef) return null; 1096 + if (!itemDef) { 1097 + throw new Error( 1098 + "Failed to convert array item type to lexicon definition", 1099 + ); 1100 + } 1082 1101 1083 1102 const arrayDef: LexiconArray = { type: "array", items: itemDef }; 1084 1103 ··· 1092 1111 return arrayDef; 1093 1112 } 1094 1113 1095 - return null; 1114 + throw new Error("Array type must have a valid item type argument"); 1096 1115 } 1097 1116 1098 1117 private getLexiconPath(lexiconId: string): string {