diff --git a/packages/jsii/lib/transforms/deprecation-warnings.ts b/packages/jsii/lib/transforms/deprecation-warnings.ts index a157592c63..07c0e01ee0 100644 --- a/packages/jsii/lib/transforms/deprecation-warnings.ts +++ b/packages/jsii/lib/transforms/deprecation-warnings.ts @@ -42,10 +42,7 @@ export class DeprecationWarningsInjector { ), ); - if ( - spec.isDeprecated(type) && - (spec.isEnumType(type) || (spec.isInterfaceType(type) && type.datatype)) - ) { + if (spec.isDeprecated(type) && spec.isEnumType(type)) { // The type is deprecated statements.push( createWarningFunctionCall(type.fqn, type.docs?.deprecated), @@ -78,12 +75,14 @@ export class DeprecationWarningsInjector { } } else if (spec.isInterfaceType(type) && type.datatype) { for (const prop of Object.values(type.properties ?? {})) { - if (spec.isDeprecated(prop)) { - // The property is deprecated + if (spec.isDeprecated(prop) || spec.isDeprecated(type)) { + // If the property individually is deprecated, or the entire type is deprecated + const deprecatedDocs = + prop.docs?.deprecated ?? type.docs?.deprecated; statements.push( createWarningFunctionCall( `${type.fqn}#${prop.name}`, - prop.docs?.deprecated, + deprecatedDocs, ts.createIdentifier(`"${prop.name}" in ${PARAMETER_NAME}`), ), ); diff --git a/packages/jsii/test/deprecation-warnings.test.ts b/packages/jsii/test/deprecation-warnings.test.ts index 2959608845..17d5e203d9 100644 --- a/packages/jsii/test/deprecation-warnings.test.ts +++ b/packages/jsii/test/deprecation-warnings.test.ts @@ -266,6 +266,29 @@ function testpkg_Baz(p) { `); }); + test('generates calls for deprecated interface', async () => { + const result = await compileJsiiForTest( + ` + /** @deprecated use Bar instead */ + export interface Foo { + readonly bar: string; + } + `, + undefined /* callback */, + { addDeprecationWarnings: true }, + ); + + expect(jsFile(result, '.warnings.jsii')).toMatch(`function testpkg_Foo(p) { + if (p == null) + return; + visitedObjects.add(p); + if ("bar" in p) + print("testpkg.Foo#bar", "use Bar instead"); + visitedObjects.delete(p); +} +`); + }); + test('generates calls for types in other assemblies', async () => { const calcBaseRoot = resolveModuleDir('@scope/jsii-calc-base'); const calcLibRoot = resolveModuleDir('@scope/jsii-calc-lib');