diff --git a/core/src/components/alert/alert.tsx b/core/src/components/alert/alert.tsx index ca367a50a9..8e8c8ad7a1 100644 --- a/core/src/components/alert/alert.tsx +++ b/core/src/components/alert/alert.tsx @@ -21,8 +21,8 @@ import mdLeaveAnimation from './animations/md.leave'; }) export class Alert implements OverlayInterface { - private activeId: string; - private inputType: string | null = null; + private activeId: string | undefined; + private inputType: string | undefined; private hdrId: string; presented = false; @@ -266,7 +266,7 @@ export class Alert implements OverlayInterface { // return an object of all the values with the input name as the key const values: {[k: string]: string} = {}; this.inputs.forEach(i => { - values[i.name] = i.value; + values[i.name] = i.value || ''; }); console.debug('returning', values); @@ -407,7 +407,7 @@ export class Alert implements OverlayInterface { console.warn(`Alert cannot mix input types: ${(inputTypes.join('/'))}. Please see alert docs for more info.`); } - this.inputType = inputTypes.length > 0 ? inputTypes[0] : null; + this.inputType = inputTypes.length > 0 ? inputTypes[0] : undefined; return [ , diff --git a/core/src/components/animation-controller/animation-interface.tsx b/core/src/components/animation-controller/animation-interface.tsx index aa2de19145..962d49f504 100644 --- a/core/src/components/animation-controller/animation-interface.tsx +++ b/core/src/components/animation-controller/animation-interface.tsx @@ -65,6 +65,6 @@ export interface EffectProperty { export interface EffectState { val: any; - num: number|null; + num: number; effectUnit: string; } diff --git a/core/src/components/animation-controller/animator.tsx b/core/src/components/animation-controller/animator.tsx index 23c6ce3136..40954ca55a 100644 --- a/core/src/components/animation-controller/animator.tsx +++ b/core/src/components/animation-controller/animator.tsx @@ -211,20 +211,21 @@ export class Animator { // add from/to EffectState to the EffectProperty const fxState: EffectState = { val: val, - num: null, + num: 0, effectUnit: '', }; fxProp[state] = fxState; if (typeof val === 'string' && val.indexOf(' ') < 0) { const r = val.match(CSS_VALUE_REGEX); - const num = parseFloat(r[1]); + if (r) { + const num = parseFloat(r[1]); - if (!isNaN(num)) { - fxState.num = num; + if (!isNaN(num)) { + fxState.num = num; + } + fxState.effectUnit = (r[0] !== r[2] ? r[2] : ''); } - fxState.effectUnit = (r[0] !== r[2] ? r[2] : ''); - } else if (typeof val === 'number') { fxState.num = val; } @@ -972,19 +973,18 @@ export class Animator { * NO RECURSION */ _willChange(addWillChange: boolean) { - let i = 0; let wc: string[]; const effects = this._fxProperties; let willChange: string; if (addWillChange && effects) { wc = []; - for (i = 0; i < effects.length; i++) { + for (let i = 0; i < effects.length; i++) { const propWC = effects[i].wc; if (propWC === 'webkitTransform') { wc.push('transform', '-webkit-transform'); - } else { + } else if (propWC) { wc.push(propWC); } } @@ -994,9 +994,12 @@ export class Animator { willChange = ''; } - for (i = 0; i < this._elementTotal; i++) { - // ******** DOM WRITE **************** - (this._elements[i] as any).style.willChange = willChange; + const elements = this._elements; + if (elements) { + for (let i = 0; i < this._elementTotal; i++) { + // ******** DOM WRITE **************** + (elements[i] as any).style.willChange = willChange; + } } } @@ -1057,7 +1060,7 @@ export class Animator { if (this._isReverse) { // if the animation is going in reverse then // flip the step value: 0 becomes 1, 1 becomes 0 - currentStepValue = ((currentStepValue * -1) + 1); + currentStepValue = 1 - currentStepValue; } const stepValue = shouldComplete ? 1 : 0; @@ -1065,10 +1068,10 @@ export class Animator { if (dur === undefined) { dur = -1; } - if (diff < 0.05) { + if (dur < 0) { + dur = this._duration || 0; + } else if (diff < 0.05) { dur = 0; - } else if (dur < 0) { - dur = this._duration; } this._isAsync = (dur > 30); diff --git a/core/src/components/animation-controller/transition-end.ts b/core/src/components/animation-controller/transition-end.ts index fbeea6b546..830ccfa9cd 100644 --- a/core/src/components/animation-controller/transition-end.ts +++ b/core/src/components/animation-controller/transition-end.ts @@ -1,30 +1,26 @@ -export function transitionEnd(el: HTMLElement, callback: {(ev?: TransitionEvent): void}) { +export function transitionEnd(el: HTMLElement|null, callback: {(ev?: TransitionEvent): void}) { let unRegTrans: Function; - let unRegWKTrans: Function; const opts: any = { passive: true }; function unregister() { - unRegWKTrans && unRegWKTrans(); unRegTrans && unRegTrans(); } - function onTransitionEnd(ev: TransitionEvent) { + function onTransitionEnd(ev: Event) { if (el === ev.target) { unregister(); - callback(ev); + callback(ev as TransitionEvent); } } if (el) { el.addEventListener('webkitTransitionEnd', onTransitionEnd, opts); - unRegWKTrans = function() { - el.removeEventListener('webkitTransitionEnd', onTransitionEnd, opts); - }; - el.addEventListener('transitionend', onTransitionEnd, opts); + unRegTrans = function() { + el.removeEventListener('webkitTransitionEnd', onTransitionEnd, opts); el.removeEventListener('transitionend', onTransitionEnd, opts); }; } diff --git a/core/src/components/datetime/datetime-util.ts b/core/src/components/datetime/datetime-util.ts index f2437eed47..fab4b713f0 100644 --- a/core/src/components/datetime/datetime-util.ts +++ b/core/src/components/datetime/datetime-util.ts @@ -35,7 +35,7 @@ export function renderDatetime(template: string, value: DatetimeData, locale: Lo } -export function renderTextFormat(format: string, value: any, date: DatetimeData, locale: LocaleData): string { +export function renderTextFormat(format: string, value: any, date: DatetimeData|null, locale: LocaleData): string { if (format === FORMAT_DDDD || format === FORMAT_DDD) { try { @@ -55,11 +55,11 @@ export function renderTextFormat(format: string, value: any, date: DatetimeData, } if (format === FORMAT_A) { - return date ? date.hour < 12 ? 'AM' : 'PM' : value ? value.toUpperCase() : ''; + return date && date.hour ? date.hour < 12 ? 'AM' : 'PM' : value ? value.toUpperCase() : ''; } if (format === FORMAT_a) { - return date ? date.hour < 12 ? 'am' : 'pm' : value ? value : ''; + return date && date.hour ? date.hour < 12 ? 'am' : 'pm' : value ? value : ''; } if (isBlank(value)) { @@ -102,45 +102,48 @@ export function renderTextFormat(format: string, value: any, date: DatetimeData, export function dateValueRange(format: string, min: DatetimeData, max: DatetimeData): any[] { const opts: any[] = []; - let i: number; if (format === FORMAT_YYYY || format === FORMAT_YY) { // year - i = max.year; - while (i >= min.year) { - opts.push(i--); + if (!max.year || !min.year) { + throw new Error('min and max year is undefined'); + } + + for (let i = max.year - 1; i >= min.year; i--) { + opts.push(i); } } else if (format === FORMAT_MMMM || format === FORMAT_MMM || format === FORMAT_MM || format === FORMAT_M || format === FORMAT_hh || format === FORMAT_h) { + // month or 12-hour - for (i = 1; i < 13; i++) { + for (let i = 1; i < 13; i++) { opts.push(i); } } else if (format === FORMAT_DDDD || format === FORMAT_DDD || format === FORMAT_DD || format === FORMAT_D) { // day - for (i = 1; i < 32; i++) { + for (let i = 1; i < 32; i++) { opts.push(i); } } else if (format === FORMAT_HH || format === FORMAT_H) { // 24-hour - for (i = 0; i < 24; i++) { + for (let i = 0; i < 24; i++) { opts.push(i); } } else if (format === FORMAT_mm || format === FORMAT_m) { // minutes - for (i = 0; i < 60; i++) { + for (let i = 0; i < 60; i++) { opts.push(i); } } else if (format === FORMAT_ss || format === FORMAT_s) { // seconds - for (i = 0; i < 60; i++) { + for (let i = 0; i < 60; i++) { opts.push(i); } @@ -175,10 +178,10 @@ export function isLeapYear(year: number): boolean { const ISO_8601_REGEXP = /^(\d{4}|[+\-]\d{6})(?:-(\d{2})(?:-(\d{2}))?)?(?:T(\d{2}):(\d{2})(?::(\d{2})(?:\.(\d{3}))?)?(?:(Z)|([+\-])(\d{2})(?::(\d{2}))?)?)?$/; const TIME_REGEXP = /^((\d{2}):(\d{2})(?::(\d{2})(?:\.(\d{3}))?)?(?:(Z)|([+\-])(\d{2})(?::(\d{2}))?)?)?$/; -export function parseDate(val: any): DatetimeData { +export function parseDate(val: any): DatetimeData|null { // manually parse IS0 cuz Date.parse cannot be trusted // ISO 8601 format: 1994-12-15T13:47:20Z - let parse: any[]; + let parse: any[] = null; if (val && val !== '') { // try parsing for just time first, HH:MM @@ -322,7 +325,7 @@ export function getValueFromFormat(date: DatetimeData, format: string) { } -export function convertFormatToKey(format: string): string { +export function convertFormatToKey(format: string): string|null { for (const k in FORMAT_KEYS) { if (FORMAT_KEYS[k].f === format) { return FORMAT_KEYS[k].k; @@ -448,15 +451,15 @@ export function convertToArrayOfNumbers(input: any[] | string | number, type: st } -function twoDigit(val: number): string { +function twoDigit(val: number | undefined): string { return ('0' + (val ? Math.abs(val) : '0')).slice(-2); } -function threeDigit(val: number): string { +function threeDigit(val: number | undefined): string { return ('00' + (val ? Math.abs(val) : '0')).slice(-3); } -function fourDigit(val: number): string { +function fourDigit(val: number | undefined): string { return ('000' + (val ? Math.abs(val) : '0')).slice(-4); } diff --git a/core/src/components/picker/picker.tsx b/core/src/components/picker/picker.tsx index 6036cf9f29..7d6e7082d0 100644 --- a/core/src/components/picker/picker.tsx +++ b/core/src/components/picker/picker.tsx @@ -191,7 +191,7 @@ export class Picker implements OverlayInterface { } @Method() - addButton(button: any) { + addButton(button: PickerButton) { this.buttons.push(button); } @@ -201,8 +201,8 @@ export class Picker implements OverlayInterface { } @Method() - getColumn(name: string): PickerColumn { - return this.getColumns().find(column => column.name === name); + getColumn(name: string): PickerColumn|undefined { + return this.columns.find(column => column.name === name); } @Method() @@ -232,10 +232,10 @@ export class Picker implements OverlayInterface { } } - private getSelected(): any { + private getSelected() { const selected: {[k: string]: any} = {}; this.columns.forEach((col, index) => { - const selectedColumn = col.options[col.selectedIndex]; + const selectedColumn = col.selectedIndex ? col.options[col.selectedIndex] : null; selected[col.name] = { text: selectedColumn ? selectedColumn.text : null, value: selectedColumn ? selectedColumn.value : null, @@ -354,13 +354,13 @@ export interface PickerOptions { } export interface PickerColumn { - name?: string; + name: string; align?: string; selectedIndex?: number; prevSelected?: number; prefix?: string; suffix?: string; - options?: PickerColumnOption[]; + options: PickerColumnOption[]; cssClass?: string; columnWidth?: string; prefixWidth?: string; diff --git a/core/src/components/router/utils/matching.ts b/core/src/components/router/utils/matching.ts index 6f9e41c8b1..111ce5efa1 100644 --- a/core/src/components/router/utils/matching.ts +++ b/core/src/components/router/utils/matching.ts @@ -47,7 +47,7 @@ export function matchesIDs(ids: string[], chain: RouteChain): number { export function matchesPath(path: string[], chain: RouteChain): RouteChain | null { const segments = new RouterSegments(path); let matchesDefault = false; - let allparams: any[]; + let allparams: any[]|undefined = undefined; for (let i = 0; i < chain.length; i++) { const path = chain[i].path; if (path[0] === '') { @@ -125,7 +125,7 @@ export function routerIDsToChain(ids: RouteID[], chains: RouteChain[]): RouteCha export function routerPathToChain(path: string[], chains: RouteChain[]): RouteChain|null { - let match: RouteChain = null; + let match: RouteChain|null = null; let matches = 0; for (const chain of chains) { const matchedChain = matchesPath(path, chain); diff --git a/core/src/components/router/utils/path.ts b/core/src/components/router/utils/path.ts index e5b02652c4..1c856c3873 100644 --- a/core/src/components/router/utils/path.ts +++ b/core/src/components/router/utils/path.ts @@ -34,9 +34,9 @@ export function writePath(history: History, base: string, usePath: boolean, path } if (isPop) { // history.back(); - history.replaceState(state, null, url); + history.replaceState(state, '', url); } else { - history.pushState(state, null, url); + history.pushState(state, '', url); } } @@ -51,8 +51,8 @@ export function readPath(loc: Location, base: string, useHash: boolean): string[ return null; } -export function parsePath(path: string): string[] { - if (path === null || path === undefined) { +export function parsePath(path: string|null|undefined): string[] { + if (path == null) { return ['']; } const segments = path.split('/')