typespec1-5 Exercise 3: Five Decorator Mistakes ===================================================== broken5.tsp: namespace Broken5; model Item { @maxLength(10) count: int32; @minValue("one") qty: int32; @minItems(3) @maxItems(1) tags: string[]; @pattern(7) code: string; @visibility(Lifecycle.Created) note: string; } PREDICTION (from the signatures: minLength/maxLength target a string or property; maxValue's argument is a number; minItems and maxItems take integers; pattern's argument is a string) line 4 @maxLength(10) on an int32 -> decorator-wrong-target (the target must be a string) line 5 @minValue("one") -> invalid-argument: a string is not a number line 6 @minItems(3) @maxItems(1) -> invalid-range: 3..1 line 7 @pattern(7) -> invalid-argument: a number is not a string line 8 Lifecycle.Created -> invalid-ref: the enum has no member 'Created' (the phases are Create, Read, Update, and others I did not list) Compiler output: TypeSpec compiler v1.17.0 - Compiling... × Compiling Diagnostics were reported during compilation: ex/broken5.tsp:4:3 - error decorator-wrong-target: Cannot apply @maxLength decorator to type it is not a string > 4 | @maxLength(10) count: int32; | ^^^^^^^^^^^^^^ ex/broken5.tsp:5:13 - error invalid-argument: Argument of type '"one"' is not assignable to parameter of type 'valueof numeric | utcDateTime | offsetDateTime | plainDate | plainTime | duration' > 5 | @minValue("one") qty: int32; | ^^^^^ ex/broken5.tsp:6:3 - error invalid-range: Range "3..1" is invalid. > 6 | @minItems(3) @maxItems(1) tags: string[]; | ^^^^^^^^^^^^ ex/broken5.tsp:7:12 - error invalid-argument: Argument of type '7' is not assignable to parameter of type 'valueof string' > 7 | @pattern(7) code: string; | ^ ex/broken5.tsp:8:25 - error invalid-ref: Enum doesn't have member Created > 8 | @visibility(Lifecycle.Created) note: string; | ^^^^^^^ Found 5 errors. fixed5.tsp (compiles with no errors): namespace Fixed5; model Item { @maxValue(10) count: int32; @minValue(1) qty: int32; @minItems(1) @maxItems(3) tags: string[]; @pattern("^[A-Z]+$") code: string; @visibility(Lifecycle.Create) note: string; } PREDICTION CHECK All five predicted, with the right line and the right error code. The one I did not predict exactly was which column the range error points to (it points to the @minItems decorator: the range is the pair of values taken together). THE FIXES count: @maxValue(10), because the number needs a number rule. qty: @minValue(1). tags: the range written the right way round, (1, 3). code: a string pattern. note: Lifecycle.Create. WHY THIS WORKS AS AN ANSWER --------------------------- The compiler reports all five in one run because they are independent. Every message can be predicted from the decorator's signature, which is in the library's own .tsp files: reading the signature first is faster than reading the message afterwards.