angular – 警告TS0:@param上的类型注释对于TypeScript类型是多余的,删除{…}部分

前端之家收集整理的这篇文章主要介绍了angular – 警告TS0:@param上的类型注释对于TypeScript类型是多余的,删除{…}部分前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我编译我的角度应用程序时收到错误

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

在utils.ts文件中,我有以下函数

/**
 * 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,eventType === "focus" ? true : false);
}

如果我删除了注释部分的@param,则错误消失,但是当我编写代码调用函数时,我也会松开额外的信息.

谁知道如何解决这个问题?

解决方法

解决方案是从注释中删除{},错误不再是:

/**
 * @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)
 */

它接缝你不需要在JsDoc上的TypeScript上指定字段的类型(我在here中找到了该信息).

发生这种情况是因为JsDocs解释代码并且已经知道您在函数的参数上声明了哪种类型,因此,您不再需要在注释上声明它们.

猜你在找的Angularjs相关文章