Skip to content

Commit d973bac

Browse files
Do not emit deprecated-implicit-optionality when in an op is (#10599)
Makes this warning less aggressive
1 parent 2143f3d commit d973bac

3 files changed

Lines changed: 29 additions & 4 deletions

File tree

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
changeKind: internal
3+
packages:
4+
- "@typespec/http"
5+
---
6+
7+
Do not emit deprecated-implicit-optionality on op is

packages/http/src/decorators.ts

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -418,10 +418,18 @@ export const $patch: PatchDecorator = (
418418

419419
if (options) {
420420
if (options.implicitOptionality === true) {
421-
reportDiagnostic(context.program, {
422-
code: "deprecated-implicit-optionality",
423-
target: entity,
424-
});
421+
// Only emit the deprecation warning on the original use of the decorator,
422+
// not when inherited via `op is`.
423+
const decoratorNode = context.decoratorTarget as any;
424+
if (
425+
decoratorNode.kind !== SyntaxKind.DecoratorExpression ||
426+
decoratorNode.parent === entity.node
427+
) {
428+
reportDiagnostic(context.program, {
429+
code: "deprecated-implicit-optionality",
430+
target: entity,
431+
});
432+
}
425433
}
426434
setPatchOptions(context.program, entity, options);
427435
}

packages/http/test/http-decorators.test.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,16 @@ describe("http: decorators", () => {
7070

7171
expectDiagnosticEmpty(diagnostics);
7272
});
73+
74+
it(`@patch does not emit deprecation warning when inherited via 'op is'`, async () => {
75+
const diagnostics = await Tester.diagnose(`
76+
@route("/base") #suppress "@typespec/http/deprecated-implicit-optionality" "testing"
77+
@patch(#{ implicitOptionality: true }) op base(): string;
78+
@route("/derived") op derived is base;
79+
`);
80+
81+
expectDiagnosticEmpty(diagnostics);
82+
});
7383
});
7484

7585
describe("@header", () => {

0 commit comments

Comments
 (0)