-
Notifications
You must be signed in to change notification settings - Fork 14
Update index.ts #35
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Update index.ts #35
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -74,7 +74,7 @@ export function ShortcutButtonsPlugin(config: ShortcutButtonsFlatpickr.Config) { | |
/** | ||
* Element that wraps this plugin's dependent elements. | ||
*/ | ||
let wrapper: HTMLElement; | ||
let wrapper: HTMLElement | undefined; | ||
|
||
/** | ||
* Handles click events on plugin's button. | ||
|
@@ -88,7 +88,7 @@ export function ShortcutButtonsPlugin(config: ShortcutButtonsFlatpickr.Config) { | |
return; | ||
} | ||
|
||
const index = parseInt(target.dataset.index, 10); | ||
const index = parseInt(target.dataset.index as string, 10); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @jcsmorais index could be undefined, that's why I get TS error --> |
||
|
||
const callbacks: ShortcutButtonsFlatpickr.OnClickSignature[] = Array.isArray(cfg.onClick) ? | ||
cfg.onClick : | ||
|
@@ -119,7 +119,7 @@ export function ShortcutButtonsPlugin(config: ShortcutButtonsFlatpickr.Config) { | |
/** | ||
* Set given button's attributes. | ||
*/ | ||
function setButtonsAttributes(button: HTMLButtonElement, attributes?: ShortcutButtonsFlatpickr.Attributes) { | ||
function setButtonsAttributes(button: HTMLButtonElement, attributes: ShortcutButtonsFlatpickr.Attributes) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @jcsmorais your are checking for undefined before calling this function, no need for attributes to be optional |
||
Object.keys(attributes).filter((attribute) => supportedAttributes.has(attribute)).forEach((key) => { | ||
if (key === 'class') { | ||
button.classList.add(attributes[key]); | ||
|
@@ -136,7 +136,7 @@ export function ShortcutButtonsPlugin(config: ShortcutButtonsFlatpickr.Config) { | |
*/ | ||
onReady: () => { | ||
wrapper = document.createElement('div'); | ||
wrapper.classList.add('shortcut-buttons-flatpickr-wrapper', cfg.theme); | ||
wrapper.classList.add('shortcut-buttons-flatpickr-wrapper', cfg.theme as string); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @jcsmorais theme is defined as string | undefined (gives TS error) but you're always setting a default theme, therefore it's never undefined at this point, simpliest way is to use "as string" |
||
|
||
if (typeof cfg.label !== 'undefined' && cfg.label.length) { | ||
const label = document.createElement('div'); | ||
|
@@ -176,6 +176,7 @@ export function ShortcutButtonsPlugin(config: ShortcutButtonsFlatpickr.Config) { | |
* Clean up before flatpickr is destroyed. | ||
*/ | ||
onDestroy: () => { | ||
if (typeof wrapper === 'undefined') return; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @jcsmorais changed this alike your suggestion |
||
wrapper.removeEventListener('keydown', onKeyDown); | ||
wrapper.removeEventListener('click', onClick); | ||
wrapper = undefined; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jcsmorais can be undefined bc its set to undefined onDestroy(), I get TS errors if it's not defined that way