From 00fdefc08020f394f67893ce96f819a65103ae7a Mon Sep 17 00:00:00 2001 From: Alan Choi Date: Thu, 17 Jan 2019 18:36:56 +0900 Subject: [PATCH] Make constructor parameter optional --- types/mousetrap/index.d.ts | 2 +- types/mousetrap/test/index.ts | 6 +++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/types/mousetrap/index.d.ts b/types/mousetrap/index.d.ts index d55559e3af..e1ab447a65 100644 --- a/types/mousetrap/index.d.ts +++ b/types/mousetrap/index.d.ts @@ -10,7 +10,7 @@ interface ExtendedKeyboardEvent extends KeyboardEvent { interface MousetrapStatic { (el: Element): MousetrapInstance; - new (el: Element): MousetrapInstance; + new (el?: Element): MousetrapInstance; addKeycodes(keycodes: { [key: number]: string }): void; stopCallback: (e: ExtendedKeyboardEvent, element: Element, combo: string) => boolean; bind(keys: string|string[], callback: (e: ExtendedKeyboardEvent, combo: string) => any, action?: string): void; diff --git a/types/mousetrap/test/index.ts b/types/mousetrap/test/index.ts index fae472b76f..13d1ea5c36 100644 --- a/types/mousetrap/test/index.ts +++ b/types/mousetrap/test/index.ts @@ -49,7 +49,11 @@ Mousetrap.reset(); // event handler to the form element only, instead of the entire document. var element = document.querySelector('form'); var instance = new Mousetrap(element); -instance.bind('mod+s', function(){ console.log('Instance Saved'); }); +instance.bind('mod+s', function () { console.log('Instance Saved'); }); + +// Test that we can create an instance of mousetrap without passing element to the constructor. +var documentInstance = new Mousetrap(); +documentInstance.bind('mod+s', function () { console.log('documentInstance Saved'); }); // Test that the factory method works as well. Mousetrap(element).bind('mod+s', function(){ console.log('Factory Saved'); });