gpt4 book ai didi

angular - 警告 TS0 : the type annotation on @param is redundant with its TypeScript type, 删除 {...} 部分

转载 作者:太空狗 更新时间:2023-10-29 17:42:24 26 4
gpt4 key购买 nike

我在编译 Angular 应用程序时遇到错误:

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, domElement.eventListenerHandler[domElementType], 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 解释代码并且已经知道您在函数参数上声明的类型,因此您不再需要在注释上声明它们。

关于angular - 警告 TS0 : the type annotation on @param is redundant with its TypeScript type, 删除 {...} 部分,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51380143/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com