diff --git a/common/changes/@typespec/compiler/booleanTrueFix_2023-10-17-22-35.json b/common/changes/@typespec/compiler/booleanTrueFix_2023-10-17-22-35.json new file mode 100644 index 00000000000..e7f13ba3191 --- /dev/null +++ b/common/changes/@typespec/compiler/booleanTrueFix_2023-10-17-22-35.json @@ -0,0 +1,10 @@ +{ + "changes": [ + { + "packageName": "@typespec/compiler", + "comment": "Fix issue where true and false were not treated as assignable to boolean.", + "type": "none" + } + ], + "packageName": "@typespec/compiler" +} \ No newline at end of file diff --git a/common/changes/@typespec/openapi3/booleanTrueFix_2023-10-17-22-35.json b/common/changes/@typespec/openapi3/booleanTrueFix_2023-10-17-22-35.json new file mode 100644 index 00000000000..d9a70151de5 --- /dev/null +++ b/common/changes/@typespec/openapi3/booleanTrueFix_2023-10-17-22-35.json @@ -0,0 +1,10 @@ +{ + "changes": [ + { + "packageName": "@typespec/openapi3", + "comment": "", + "type": "none" + } + ], + "packageName": "@typespec/openapi3" +} \ No newline at end of file diff --git a/packages/compiler/src/core/checker.ts b/packages/compiler/src/core/checker.ts index 0a36f675b9c..59c2fd9877b 100644 --- a/packages/compiler/src/core/checker.ts +++ b/packages/compiler/src/core/checker.ts @@ -5253,6 +5253,10 @@ export function createChecker(program: Program): Checker { return source.kind === ReflectionNameToKind[target.name]; } + if (source.kind === "Boolean" && target.kind === "Scalar" && target.name === "boolean") { + return true; + } + if (target.kind === "Scalar") { return isRelatedToScalar(source, target); } diff --git a/packages/openapi3/test/overloads.test.ts b/packages/openapi3/test/overloads.test.ts index 102b34d336b..5aaceb21c39 100644 --- a/packages/openapi3/test/overloads.test.ts +++ b/packages/openapi3/test/overloads.test.ts @@ -109,4 +109,19 @@ describe("openapi3: overloads", () => { } `); }); + + it("can overload a boolean property with true or false", async () => { + const _ = await openApiFor(` + @test + op someThing(param: boolean): string | int32; + + @test + @overload(someThing) + op someStringThing(param: true): string; + + @test + @overload(someThing) + op someNumberThing(param: false): int32; + `); + }); });