TypeScript/tests/cases/fourslash/jsDocInheritDoc.ts
Sean Barag a46d2705ef Use documentation comments from inherited properties when @inheritDoc is present (#18804)
* Use documentation comments from inherited properties when @inheritDoc is present

The JSDoc `@ineheritDoc` [tag](http://usejsdoc.org/tags-inheritdoc.html)
"indicates that a symbol should inherit its documentation from its
parent class".  In the case of a TypeScript file, this also includes
implemented interfaces and parent interfaces.

With this change, a class method or property (or an interface property)
with the `@inheritDoc` tag in its JSDoc comment will automatically use
the comments from its nearest ancestor that has no `@inheritDoc` tag.
To prevent breaking backwards compatibility,
`Symbol.getDocumentationComment` now accepts an optional `TypeChecker`
instance to support this feature.

fixes #8912

* Use ts.getJSDocTags as per @andy-ms 's recommendation

* Convert @inheritDoc tests to verify.quickInfoAt

* Concatenate inherited and local docs when @inheritDoc is present

* Make typeChecker param explicitly `TypeChecker | undefined`

* Re-accept baseline after switch to explicit `| undefined`

* Update APISample_jsodc.ts to match new getDocumentationComment signature

* Re-accept baselines after rebasing
2017-11-06 13:18:21 -08:00

58 lines
1.8 KiB
TypeScript

///<reference path="fourslash.ts" />
// @Filename: inheritDoc.ts
////class Foo {
//// /**
//// * Foo constructor documentation
//// */
//// constructor(value: number) {}
//// /**
//// * Foo#method1 documentation
//// */
//// static method1() {}
//// /**
//// * Foo#method2 documentation
//// */
//// method2() {}
//// /**
//// * Foo#property1 documentation
//// */
//// property1: string;
////}
////interface Baz {
//// /** Baz#property1 documentation */
//// property1: string;
//// /**
//// * Baz#property2 documentation
//// */
//// property2: object;
////}
////class Bar extends Foo implements Baz {
//// ctorValue: number;
//// /** @inheritDoc */
//// constructor(value: number) {
//// super(value);
//// this.ctorValue = value;
//// }
//// /** @inheritDoc */
//// static method1() {}
//// method2() {}
//// /** @inheritDoc */
//// property1: string;
//// /**
//// * Bar#property2
//// * @inheritDoc
//// */
//// property2: object;
////}
////const b = new Bar/*1*/(5);
////b.method2/*2*/();
////Bar.method1/*3*/();
////const p1 = b.property1/*4*/;
////const p2 = b.property2/*5*/;
verify.quickInfoAt("1", "constructor Bar(value: number): Bar", undefined); // constructors aren't actually inherited
verify.quickInfoAt("2", "(method) Bar.method2(): void", "Foo#method2 documentation"); // use inherited docs only
verify.quickInfoAt("3", "(method) Bar.method1(): void", undefined); // statics aren't actually inherited
verify.quickInfoAt("4", "(property) Bar.property1: string", "Foo#property1 documentation"); // use inherited docs only
verify.quickInfoAt("5", "(property) Bar.property2: object", "Baz#property2 documentation\nBar#property2"); // include local and inherited docs