fix(all): ts strict (part 4)

This commit is contained in:
Manu Mtz.-Almeida
2018-03-21 11:27:59 +01:00
parent 779f02c932
commit 4693229c84
8 changed files with 63 additions and 61 deletions

View File

@ -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 [
<ion-backdrop tappable={this.enableBackdropDismiss}/>,

View File

@ -65,6 +65,6 @@ export interface EffectProperty {
export interface EffectState {
val: any;
num: number|null;
num: number;
effectUnit: string;
}

View File

@ -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);
if (r) {
const num = parseFloat(r[1]);
if (!isNaN(num)) {
fxState.num = num;
}
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++) {
const elements = this._elements;
if (elements) {
for (let i = 0; i < this._elementTotal; i++) {
// ******** DOM WRITE ****************
(this._elements[i] as any).style.willChange = willChange;
(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);

View File

@ -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);
};
}

View File

@ -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);
}

View File

@ -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;

View File

@ -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);

View File

@ -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('/')