[英]Typescript function returntype
我在 af 模塊中有這個 function 聲明:
declare module 'picoapp' {
export function component(node?: HTMLElement): void
}
然后在.ts文件中像這樣使用它
export default component((node: HTMLElement) => {
// All sorts of TS/JS here
})
但是 VSCode 給了我這個警告: Argument of type '(node: HTMLElement) => void' is not assignable to parameter of type 'HTMLElement'
。
那么 function 的返回類型應該是什么? 我沒有返回值,而只是使用節點作為參考。
如果您的組件 function 的用法是正確的,則應將類型聲明如下,其中回調可以是您喜歡的任何名稱。
declare module 'picoapp' { export function component(callback:(node?: HTMLElement)=>void): void }
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.