KeyboardJS icon indicating copy to clipboard operation
KeyboardJS copied to clipboard

Error TypeScript type

Open TomKongHaoWei opened this issue 4 years ago • 2 comments

Describe the bug The type of the 'e' parameter is not exported, Although I can use any to get around ts, But it's not elegant

Example code

keyboardjs.bind(
  'a', 
  (e: KeyEvent) => {
    e.preventRepeat(); 
    console.log('a', e);
  },
  (e: any) => {
    console.log('a', e);
  }
);

Expected behavior Want to show how to write the 'e' type

Enviroment (please include the following info):

  • OS: Windows
  • Browser: Chrome
  • Version: keyboardjs v2.6.4 @types/keyboardjs v2.5.0

TomKongHaoWei avatar Mar 15 '22 06:03 TomKongHaoWei

My demo code

image

TomKongHaoWei avatar Mar 15 '22 06:03 TomKongHaoWei

Problem solved. I forgot to put a question mark: keyboardJS.bind( 'a', (e?: KeyEvent) => { // 按下 e?.preventRepeat(); console.log('a按下', e); }, (e?: KeyEvent) => { // 释放 console.log('a释放', e); } );

TomKongHaoWei avatar Mar 31 '22 12:03 TomKongHaoWei

Glad you found a solution. I'd like to do a redux of the library soon and modernize it. I'll keep this issue in mind in regards to developer expectations.

RobertWHurst avatar Aug 27 '22 01:08 RobertWHurst