pikaday: Enable strictNullChecks, noImplicitThis

This commit is contained in:
Michael Heasell
2019-02-24 00:51:07 +00:00
parent ce69227629
commit 828fb4392a
3 changed files with 17 additions and 13 deletions
+7 -7
View File
@@ -36,7 +36,7 @@ declare class Pikaday {
* Returns a JavaScript Date object for the selected day, or null if
* no date is selected.
*/
getDate(): Date;
getDate(): Date | null;
/**
* Set the current selection. This will be restricted within the bounds
@@ -50,7 +50,7 @@ declare class Pikaday {
* Returns a Moment.js object for the selected date (Moment must be
* loaded before Pikaday).
*/
getMoment(): moment.Moment;
getMoment(): moment.Moment | null;
/**
* Set the current selection with a Moment.js object (see setDate).
@@ -159,7 +159,7 @@ declare namespace Pikaday {
/**
* Bind the datepicker to a form field.
*/
field?: HTMLElement;
field?: HTMLElement | null;
/**
* The default output format for toString() and field value.
@@ -171,7 +171,7 @@ declare namespace Pikaday {
* Use a different element to trigger opening the datepicker.
* Default: field element.
*/
trigger?: HTMLElement;
trigger?: HTMLElement | null;
/**
* Automatically show/hide the datepicker on field focus.
@@ -201,7 +201,7 @@ declare namespace Pikaday {
* DOM node to render calendar into, see container example.
* Default: undefined.
*/
container?: HTMLElement;
container?: HTMLElement | null;
/**
* The initial date to view when first opened.
@@ -330,12 +330,12 @@ declare namespace Pikaday {
* Function which will be used for parsing input string and getting a date object from it.
* This function will take precedence over moment.
*/
parse?(date: string, format: string): Date;
parse?(date: string, format: string): Date | null;
/**
* Callback function for when a date is selected.
*/
onSelect?(date: Date): void;
onSelect?(this: Pikaday, date: Date): void;
/**
* Callback function for when the picker becomes visible.
+7 -3
View File
@@ -14,15 +14,15 @@ new Pikaday({field: $('#datepicker')[0]});
console.log(date.toISOString());
}
});
field.parentNode.insertBefore(picker.el, field.nextSibling);
field.parentNode!.insertBefore(picker.el, field.nextSibling);
})();
(() => {
const picker = new Pikaday({
field: document.getElementById('datepicker'),
format: 'D MMM YYYY',
onSelect: () => {
console.log(this.getMoment().format('Do MMMM YYYY'));
onSelect() {
console.log(this.getMoment()!.format('Do MMMM YYYY'));
}
});
@@ -116,3 +116,7 @@ new Pikaday({field: $('#datepicker')[0]});
toString: (date, format) => '2017-08-23'
});
})();
new Pikaday({
parse: (date) => null
});
+3 -3
View File
@@ -6,8 +6,8 @@
"dom"
],
"noImplicitAny": true,
"noImplicitThis": false,
"strictNullChecks": false,
"noImplicitThis": true,
"strictNullChecks": true,
"strictFunctionTypes": true,
"baseUrl": "../",
"typeRoots": [
@@ -21,4 +21,4 @@
"index.d.ts",
"pikaday-tests.ts"
]
}
}