typespec1-7 Exercise 3: Three Versioning Mistakes ======================================================= bad7.tsp: import "@typespec/http"; import "@typespec/versioning"; using Http; using TypeSpec.Versioning; @versioned(Versions) @service namespace Bad7; enum Versions { v1: "1.0", v2: "2.0" } @added(Versions.v2) model Tag { name: string; } model Item { title: string; @madeRequired(Versions.v2) code?: string; tags: Tag[]; } @route("/items") interface Items { @get list(): Item[]; @added(Versions.v1) @route("tags") @get tags(): Tag[]; } PREDICTION line 17 @madeRequired on code? -> made-required-optional: the property must be declared without ? line 18 tags: Tag[] in Item -> incompatible-versioned-reference: Item.tags is not versioned but Tag was added in v2 line 23 @added(v1) tags() returns Tag[] -> incompatible-versioned-reference: the operation is older than the model it returns Three errors expected. Compiler output: ex/bad7.tsp:17:30 - error @typespec/versioning/made-required-optional: Property 'code?' marked with @madeRequired but is optional. Should be 'code' > 17 | @madeRequired(Versions.v2) code?: string; | ^^^^ ex/bad7.tsp:18:3 - error @typespec/versioning/incompatible-versioned-reference: 'Bad7.Item.tags' is referencing versioned type 'Bad7.Tag' but is not versioned itself. > 18 | tags: Tag[]; | ^^^^ ex/bad7.tsp:23:43 - error @typespec/versioning/incompatible-versioned-reference: 'Bad7.Items.tags' was added in version 'v1' but referencing type 'Bad7.Tag' added in version 'v2'. > 23 | @added(Versions.v1) @route("tags") @get tags(): Tag[]; | ^^^^ Found 3 errors. PREDICTION CHECK Exactly the three predicted, in that order, at the lines I expected. THE FIXES code: drop the ? (@madeRequired(Versions.v2) code: string;). tags: add @added(Versions.v2) so it appears with Tag. The operation: change to @added(Versions.v2). Re-compiled with those three changes (fixed7.tsp): 'Compilation completed successfully.' WHY THIS WORKS AS AN ANSWER --------------------------- The messages name both the thing and the version, which makes them predictable from the rule 'nothing may refer to something that does not yet exist'. Note what is NOT in this list: a removed-before-added mistake in the chapter's own example was not reported.