typespec1-3 Exercise 3: Four Model Errors ================================================ broken3.tsp: namespace Broken3; model Account { id: string; balance: decimal; } model Savings extends Account { id: int32; rate: float64 = "high"; } model Statement { id: string; id: string; owner: Acount; } PREDICTION (from reading the source) line 9 id: int32 in Savings -> Account already has id: string; a subtype cannot change an inherited property's type line 10 rate: float64 = "high" -> a string default for a number line 15 id twice in Statement -> a duplicate property line 16 owner: Acount -> a typo for Account Compiler output, then the fixed file: $ tsp compile broken3.tsp --no-emit ex/broken3.tsp:9:3 - error override-property-mismatch: Model has an inherited property named id of type int32 which cannot override type string ex/broken3.tsp:10:19 - error unassignable: Type '"high"' is not assignable to type 'float64' ex/broken3.tsp:15:3 - error duplicate-property: Model Statement already has a property named id ex/broken3.tsp:16:10 - error invalid-ref: Unknown identifier Acount Found 4 errors. $ tsp compile fixed3.tsp --no-emit Compilation completed successfully. fixed3.tsp: namespace Fixed3; model Account { id: string; balance: decimal; } model Savings extends Account { rate: float64 = 0.02; } model Statement { id: string; owner: Account; } THE FIXES Savings: the redeclared id is deleted (it is inherited from Account; redeclaring it with the same type would also be allowed). The default becomes 0.02. Statement: the second id is deleted. Account is spelled correctly. WHY THIS WORKS AS AN ANSWER --------------------------- All four errors are about names and types that disagree, and the compiler finds all of them in one run with the exact line and column. The override error is the interesting one: it is the compiler enforcing that a Savings can stand wherever an Account is expected, which is the property a client of an allOf relies on.