我编译我的角度应用程序时收到错误:
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
/** * 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中找到了该信息).