typespec1-1 Exercise 3: Four Compiler Errors ================================================== broken.tsp: @service(#{ title: "Shelf Service" }) namespace ShelfService; model Shelf { id: string; capacity: int; } @route("/shelves") interface Shelves { @get list(): Shelff[]; } PREDICTION (from reading the source) line 6 capacity: int -> int is not a TypeSpec type line 9 @route(...) -> no import of the HTTP library, so @route is unknown line 11 Shelff[] -> a typo for Shelf line 11 @get -> unknown for the same reason as @route Output of the compiler, then of the fixed file: $ tsp compile broken.tsp Diagnostics were reported during compilation: ex/broken.tsp:6:13 - error invalid-ref: Unknown identifier int ex/broken.tsp:9:2 - error invalid-ref: Unknown decorator @route ex/broken.tsp:11:16 - error invalid-ref: Unknown identifier Shelff ex/broken.tsp:11:4 - error invalid-ref: Unknown decorator @get Found 4 errors. $ tsp compile fixed.tsp Compilation completed successfully. fixed.tsp: import "@typespec/http"; using Http; @service(#{ title: "Shelf Service" }) namespace ShelfService; model Shelf { id: string; capacity: int32; } @route("/shelves") interface Shelves { @get list(): Shelf[]; } THE FIXES import "@typespec/http"; and using Http; (two of the four errors disappear at once) int becomes int32 (a sized integer; integer also compiles) Shelff becomes Shelf WHY THIS WORKS AS AN ANSWER --------------------------- The four diagnostics come from three causes, and two of them (@route and @get) share one cause: the HTTP library was never loaded. That is why it pays to fix errors from the top of the file and recompile, because later errors are sometimes consequences. Note that the compiler listed the errors in an order that is not strictly top to bottom (line 6, then 9, then 11 twice, with the column of @get after the typo's): do not rely on the order, read each line number.