microsoft / microsoft/TypeScript

JSDoc: @inheritDoc disregards optionality of parameters from parent class method

Abierto
#37,210 2 comentarios 1 reacción 1 asignado Ver en GitHub

@sandersn ya está trabajando en esto.

Desde el 4/3/2020.

Bug Domain: JSDoc Effort: Difficult
Lenguaje dominante
Go
Estrellas
111k
Forks
14.4k
Merge medio
1 d 19 h
PR fusionados (30 d)
117

Descripción

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:

https://www.typescriptlang.org/play/?useJavaScript=true#code/MYGwhgzhAEBCkFNoG8CwAoa0D0AqXGW0u0AAmAEYQAuATmMNYViaQA5j0C2KAgrfQCeAHgCWXNgHta1ABQAiAHTYAMmEEJaigFYR5ASkUATBADMwAVxDUAfAF9oAbUltqAfU5CAutH5DokqbQ4Bq0MLLUktAUCMzERFhckkaipqIIRtCiAHbQbODACIZxrLQI1Ba0uch+6mIS0nJKquqaOnqGJuZWtg61ggFBIZoQiiXYzADm5WqhEP2yLu6e6voocdBlFVXQlDT0jLL6ANzMdhjn6BigkDAAIpqiAG4Z0AgAHtQI2UYw8BBINCYHD4EpkHIAC0e1DukmA4ymM1aYQWSw8AlW62BCS2lVyji8p2BlzsQA

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.

Guía de contribución

Abrir la guía de contribución

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Evaluación

Este issue todavía no se ha evaluado.

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.