打字稿事件类型注释

时间:2018-10-18 06:30:01

标签: angular typescript primeng

如何为该事件提供正确的类型注释?

控制台:

{
 originalEvent: InputEvent {isTrusted: true, data: " ", isComposing: false, 
 inputType: "insertText", dataTransfer: null, …}
 value: " "
 __proto__: Object
}

打字稿代码:

const InputEvent = (event: ??? ) => console.log(event)

有没有办法将preventdefault函数附加到此?

1 个答案:

答案 0 :(得分:0)

InputEvent.ts文件

export class InputEvent {
   isTrusted: boolean;
   data: string;
   isComposing: boolean;
   inputType: string;
   dataTransfer: string;
   //and whatever more variables you have.
}

您可以这样定义它。

const InputEvent = (event: InputEvent ) => console.log(event);