angular – 警告TS0:@param上的类型注释对于TypeScript类型是多
发布时间:2020-12-17 17:52:25 所属栏目:安全 来源:网络整理
导读:我编译我的角度应用程序时收到错误: 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文件中,我有以下函数: /**
我编译我的角度应用程序时收到错误:
在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解释代码并且已经知道您在函数的参数上声明了哪种类型,因此,您不再需要在注释上声明它们. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |