microsoft / microsoft/TypeScript
JSDoc: @inheritDoc disregards optionality of parameters from parent class method
@sandersn arbeitet bereits daran.
Seit 04.3.2020.
- Vorherrschende Sprache
- Go
- Sterne
- 111k
- Forks
- 14.3k
- Ø Merge
- 1 T. 19 Std.
- Gemergte PRs (30 T.)
- 117
Beschreibung
TypeScript Version: 3.8.3
Search Terms: inheritDoc optionality jsdoc
Code
A conceptual example of JSDoc-annotated ES6 classes I'm generating d.ts definitions for
class Base {
/**
* @abstract
* @param {Array<import("./Layer.js").default>} [opt_array] Array of layers (to be
* modified in place).
* @return {Array<import("./Layer.js").default>} Array of layers.
*/
getLayersArray(opt_array) {
return abstract();
}
}
class Derived extends Base {
/**
* @inheritDoc
*/
getLayersArray(opt_array) {
return [];
}
}
Expected behavior:
TypeScript to transpile this to something resembling this
declare class Base {
/**
* @abstract
* @param {Array<import("./Layer.js").default>} [opt_array] Array of layers (to be
* modified in place).
* @return {Array<import("./Layer.js").default>} Array of layers.
*/
getLayersArray(opt_array?: any[]): any[];
}
declare class Derived extends Base {
/**
* @inheritDoc
*/
getLayersArray(opt_array?: any): any[];
}
Actual behavior:
The optionality specifier is lost on Derived.getLayersArray
declare class Base {
/**
* @abstract
* @param {Array<import("./Layer.js").default>} [opt_array] Array of layers (to be
* modified in place).
* @return {Array<import("./Layer.js").default>} Array of layers.
*/
getLayersArray(opt_array?: any[]): any[];
}
declare class Derived extends Base {
/**
* @inheritDoc
*/
getLayersArray(opt_array: any): any[];
}
Playground Link:
Related Issues:
EDIT: In the original ES6 example, the class Derived didn't actually extend Base which led to the possibility I may have submitted an invalid report. Fixing the code sample and re-running the playground with the updated example ES6 code showed the problem to still persist. Code sample in this issue and playground link have been updated.
Beitragsleitfaden
Erste Schritte
- Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
- Forke das Repository und arbeite in einem Branch.
- Öffne einen Pull Request, der die Issue-Nummer nennt.
Bewertung
Dieses Issue wurde noch nicht bewertet.