Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

warning TS0: the type annotation on @param is redundant with its TypeScript type, remove the {...} part

I'm getting an error when I compile my angular app:

Error: ngc compilation failed: ng-formly/core/src/utils.ts(194,1): warning TS0: the type annotation on @param is redundant with its TypeScript type, remove the {...} part

In the utils.ts file, I the following function:

/**
 * Delegates the subscription of any event and assign the subscription to a particulary domElement.
 * Each Time the event is trigger, the handler function will be call
 * Ex: delegate("domElement", "focus", "input", (focus) => console.log(focus))
 * @param {any} domElement The dom element. Ex: document
 * @param {string} eventType The event type. Ex."focus" 
 * @param {string} domElementType The dom element type. Ex. "input"
 * @param {Function} author The handler function. Ex. (focus) => console.log(focus)
 */
export function delegate(domElement: any, eventType: string, domElementType: string, handler): void {
  domElement.eventListenerHandler = domElement.eventListenerHandler || {};
  if(domElement.eventListenerHandler[domElementType])
  domElement.removeEventListener(domElementType, domElement.eventListenerHandler[domElementType], eventType === "focus" ? true : false);

  domElement.eventListenerHandler[domElementType] = (event) => {
    var t = event.target;
      while (t && t !== this) {
          if (t.matches && t.matches(domElementType)) {
              handler.call(t, event);
          }
          t = t.parentNode;
      }
  }
  domElement.addEventListener(eventType, domElement.eventListenerHandler[domElementType], eventType === "focus" ? true : false);
}

If I remove the @param of the comment section, the error desapears, but I will loose as well the the extra information when I'm writing the code and call this function.

Any one knows how to solve this problem?

like image 791
Ricardo Rocha Avatar asked Jul 17 '18 11:07

Ricardo Rocha


2 Answers

The solution was to remove the {} from the comments and the error no longer is throw to:

/**
 * @param domElement The dom element. Ex: document
 * @param eventType The event type. Ex."focus" 
 * @param domElementType The dom element type. Ex. "input"
 * @param author The handler function. Ex. (focus) => console.log(focus)
 */

It seams that you don't need to specify the type of the field on TypeScript on JsDoc (I found out that information in here).

This happens because the JsDocs interprets the code and know already which type you declare on the parameters of your functions, so, you no longer need to declare them on the comments.

like image 121
Ricardo Rocha Avatar answered Oct 12 '22 21:10

Ricardo Rocha


There is configuration flag available to ignore these annotation warnings in tsconfig.json file. I set below flag to false and it stopped spitting these warnings.

"angularCompilerOptions": {
  "annotateForClosureCompiler": false
}
like image 31
Raj Avatar answered Oct 12 '22 21:10

Raj