Skip to content

Commit

Permalink
Fix #2533.
Browse files Browse the repository at this point in the history
  • Loading branch information
tjprescott committed Oct 17, 2023
1 parent bdc667a commit 01c8ad8
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -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"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"changes": [
{
"packageName": "@typespec/openapi3",
"comment": "",
"type": "none"
}
],
"packageName": "@typespec/openapi3"
}
4 changes: 4 additions & 0 deletions packages/compiler/src/core/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
15 changes: 15 additions & 0 deletions packages/openapi3/test/overloads.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
`);
});
});

0 comments on commit 01c8ad8

Please sign in to comment.