Skip to content
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

feat(common): add strict mode support #4869

Merged
merged 6 commits into from
Dec 5, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 10 additions & 6 deletions demo/src/app/common/add-nav/add-nav.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,19 @@ export class AddNavComponent {

constructor(@Inject(DOCUMENT) private document: Document) { }

goToSection(event): void {
const item: HTMLElement = event.target;
goToSection(event: Event): void {
const item: HTMLElement = event.target as HTMLElement;

if (item.dataset.anchor) {
const anchor: string = item.dataset.anchor;
const target: HTMLElement = this.document.getElementById(anchor);
const header: HTMLElement = this.document.getElementById('header');
const targetPosY: number = target.offsetTop - header.offsetHeight - 6;
window.scrollTo(0, targetPosY);
const target: HTMLElement | null = this.document.getElementById(anchor);
const header: HTMLElement | null = this.document.getElementById('header');

if (target && header) {
const targetPosY: number = target.offsetTop - header.offsetHeight - 6;

window.scrollTo(0, targetPosY);
}
}
}
}
2 changes: 1 addition & 1 deletion demo/src/app/components/+carousel/demos/dynamic/dynamic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { Component } from '@angular/core';
templateUrl: './dynamic.html'
})
export class DemoCarouselDynamicComponent {
slides = [];
slides: { image: string }[] = [];
activeSlideIndex = 0;

constructor() {
Expand Down
12 changes: 9 additions & 3 deletions demo/src/app/components/+datepicker/demo-datepicker.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,14 @@ const locales = [
nlBeLocale, nlLocale, plLocale, ptBrLocale, ruLocale, roLocale, skLocale, slLocale, svLocale, thLocale, trLocale,
zhCnLocale
];
locales.forEach((locale: LocaleData) => defineLocale(locale.abbr, locale));

locales.forEach((locale: LocaleData) => {
if (!locale.abbr) {
return;
}

defineLocale(locale.abbr, locale);
});

@NgModule({
declarations: [
Expand All @@ -44,5 +51,4 @@ locales.forEach((locale: LocaleData) => defineLocale(locale.abbr, locale));
exports: [DatepickerSectionComponent],
entryComponents: [...DEMO_COMPONENTS]
})
export class DemoDatepickerModule {
}
export class DemoDatepickerModule {}
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ import { Component } from '@angular/core';
templateUrl: './datepicker-demo.component.html'
})
export class DatepickerDemoComponent {
dt: Date = new Date();
minDate: Date = void 0;
dt: Date | undefined = new Date();
minDate: Date | undefined = void 0;
events: any[];
tomorrow: Date;
afterTomorrow: Date;
dateDisabled: { date: Date; mode: string }[];
dateDisabled: { date: Date; mode: string }[] | undefined;
formats: string[] = [
'DD-MM-YYYY',
'YYYY/MM/DD',
Expand All @@ -22,7 +22,7 @@ export class DatepickerDemoComponent {
formatYear: 'YY',
startingDay: 1
};
private opened: boolean = false;
private opened = false;

constructor() {
(this.tomorrow = new Date()).setDate(this.tomorrow.getDate() + 1);
Expand Down Expand Up @@ -54,10 +54,10 @@ export class DatepickerDemoComponent {
// todo: implement custom class cases
getDayClass(date: any, mode: string): string {
if (mode === 'day') {
let dayToCheck = new Date(date).setHours(0, 0, 0, 0);
const dayToCheck = new Date(date).setHours(0, 0, 0, 0);

for (let event of this.events) {
let currentDay = new Date(event.date).setHours(0, 0, 0, 0);
for (const event of this.events) {
const currentDay = new Date(event.date).setHours(0, 0, 0, 0);

if (dayToCheck === currentDay) {
return event.status;
Expand All @@ -82,6 +82,10 @@ export class DatepickerDemoComponent {
}

toggleMin(): void {
if (!this.minDate) {
return;
}

this.dt = new Date(this.minDate.valueOf());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { BsModalRef } from 'ngx-bootstrap/modal/bs-modal-ref.service';
templateUrl: './service-nested.html'
})
export class DemoModalServiceNestedComponent {
modalRef: BsModalRef;
modalRef: BsModalRef | null;
modalRef2: BsModalRef;
constructor(private modalService: BsModalService) {}

Expand All @@ -18,6 +18,10 @@ export class DemoModalServiceNestedComponent {
this.modalRef2 = this.modalService.show(template, { class: 'second' });
}
closeFirstModal() {
if (!this.modalRef) {
return;
}

this.modalRef.hide();
this.modalRef = null;
}
Expand Down
2 changes: 1 addition & 1 deletion demo/src/app/components/+rating/demos/dynamic/dynamic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export class DemoRatingDynamicComponent {
rate = 7;
isReadonly = false;

overStar: number;
overStar: number | undefined;
percent: number;

hoveringOver(value: number): void {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Component } from '@angular/core';
import { FormControl } from '@angular/forms';
import { AbstractControl, FormControl } from '@angular/forms';

@Component({
selector: 'demo-timepicker-custom-validation',
Expand All @@ -8,12 +8,15 @@ import { FormControl } from '@angular/forms';
export class DemoTimepickerCustomValidationComponent {
myTime: Date;

ctrl = new FormControl('', (control: FormControl) => {
ctrl = new FormControl('', (control: AbstractControl) => {
const value = control.value;

if (!value) {
return null;
}

const hours = value.getHours();

if (hours < 11 || hours > 12) {
return { outOfRange: true };
}
Expand Down
13 changes: 7 additions & 6 deletions demo/src/app/components/+timepicker/demos/dynamic/dynamic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,19 @@ import { Component } from '@angular/core';
templateUrl: './dynamic.html'
})
export class DemoTimepickerDynamicComponent {
mytime: Date = new Date();
mytime: Date | undefined = new Date();
isValid: boolean;

update(): void {
let d = new Date();
d.setHours(14);
d.setMinutes(0);
this.mytime = d;
const time = new Date();
time.setHours(14);
time.setMinutes(0);

this.mytime = time;
}

changed(): void {
console.log('Time changed to: ' + this.mytime);
console.log(`Time changed to: ${this.mytime}`);
}

clear(): void {
Expand Down
2 changes: 1 addition & 1 deletion demo/src/app/docs/api-docs/api-doc/api-doc.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ export class NgApiDocComponent {
* Returns the default value of the given directive input by first looking for it in the matching config service
* property. If there is no matching config property, it reads it from the input.
*/
defaultInputValue(input: InputDesc): string {
defaultInputValue(input: InputDesc): string | undefined {
const configProperty = this.configProperties[input.name];

return configProperty ? configProperty.defaultValue : input.defaultValue;
Expand Down
24 changes: 21 additions & 3 deletions demo/src/app/theme/style-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,26 @@ export class StyleManager {
* Set the stylesheet with the specified key.
*/
setStyle(key: string, href: string) {
getLinkElementForKey(key).setAttribute('href', href);
const linkElement = getLinkElementForKey(key);

if (!linkElement) {
return;
}

linkElement.setAttribute('href', href);
}

/**
* Remove the stylesheet with the specified key.
*/
removeStyle(key: string) {
const existingLinkElement = getExistingLinkElementByKey(key);
if (existingLinkElement) {
document.head.removeChild(existingLinkElement);

if (!existingLinkElement || !document.head) {
return;
}

document.head.removeChild(existingLinkElement);
}
}

Expand All @@ -29,13 +38,22 @@ function getLinkElementForKey(key: string) {
}

function getExistingLinkElementByKey(key: string) {
if (!document.head) {
return;
}

return document.head.querySelector(`link[rel="stylesheet"].${getClassNameForKey(key)}`);
}

function createLinkElementWithKey(key: string) {
const linkEl = document.createElement('link');
linkEl.setAttribute('rel', 'stylesheet');
linkEl.classList.add(getClassNameForKey(key));

if (!document.head) {
return;
}

document.head.appendChild(linkEl);

return linkEl;
Expand Down
11 changes: 8 additions & 3 deletions demo/src/app/theme/theme-storage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,14 @@ export class ThemeStorage {
storeTheme(theme: 'bs3' | 'bs4') {
try {
window.localStorage[ThemeStorage.storageKey] = theme;
} catch (e) {}
} catch (e) {
return null;
}

this.onThemeUpdate.emit(theme);
}

getStoredTheme(): 'bs3' | 'bs4' {
getStoredTheme(): 'bs3' | 'bs4' | null {
try {
return window.localStorage[ThemeStorage.storageKey] || null;
} catch (e) {
Expand All @@ -25,6 +28,8 @@ export class ThemeStorage {
clearStorage() {
try {
window.localStorage.removeItem(ThemeStorage.storageKey);
} catch (e) {}
} catch (e) {
return null;
}
}
}
2 changes: 1 addition & 1 deletion scripts/ci/npm-ng-latest.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@ npm i @angular/animations@latest \
@angular/service-worker@latest \
@angular-devkit/schematics@latest \
@schematics/angular@latest \
typescript@3.1.1 \
typescript@3.1.6 \
tsickle@0.33.0 \
rxjs@6.3
1 change: 0 additions & 1 deletion src/pagination/models/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ export interface ConfigModel {
pageBtnClass: string;
previousText: string;
rotate: boolean;
[key: string]: string | number | boolean;
}

export interface PagesModel {
Expand Down
2 changes: 2 additions & 0 deletions src/rating/rating.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,14 @@ export class RatingComponent implements ControlValueAccessor, OnInit {

@HostListener('keydown', ['$event'])
onKeydown(event: KeyboardEvent): void {
/* tslint:disable-next-line: deprecation */
if ([37, 38, 39, 40].indexOf(event.which) === -1) {
return;
}

event.preventDefault();
event.stopPropagation();
/* tslint:disable-next-line: deprecation */
const sign = event.which === 38 || event.which === 39 ? 1 : -1;
this.rate(this.value + sign);
}
Expand Down
6 changes: 6 additions & 0 deletions src/typeahead/typeahead.directive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -198,27 +198,31 @@ export class TypeaheadDirective implements OnInit, OnDestroy {
onChange(e: KeyboardEvent): void {
if (this._container) {
// esc
/* tslint:disable-next-line: deprecation */
if (e.keyCode === 27) {
this.hide();

return;
}

// up
/* tslint:disable-next-line: deprecation */
if (e.keyCode === 38) {
this._container.prevActiveMatch();

return;
}

// down
/* tslint:disable-next-line: deprecation */
if (e.keyCode === 40) {
this._container.nextActiveMatch();

return;
}

// enter, tab
/* tslint:disable-next-line: deprecation */
if (e.keyCode === 13) {
this._container.selectActiveMatch();

Expand Down Expand Up @@ -251,13 +255,15 @@ export class TypeaheadDirective implements OnInit, OnDestroy {
}

// if an item is visible - prevent form submission
/* tslint:disable-next-line: deprecation */
if (e.keyCode === 13) {
e.preventDefault();

return;
}

// if an item is visible - don't change focus
/* tslint:disable-next-line: deprecation */
if (e.keyCode === 9) {
e.preventDefault();
this._container.selectActiveMatch();
Expand Down
25 changes: 12 additions & 13 deletions src/utils/facade/browser.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/*tslint:disable */
/**
* @license
* Copyright Google Inc. All Rights Reserved.
Expand All @@ -10,17 +9,17 @@
/**
* JS version of browser APIs. This library can only run in the browser.
*/
var win = (typeof window !== 'undefined' && window) || <any>{};
const win = (typeof window !== 'undefined' && window) || {} as any;

export { win as window };
export var document = win.document;
export var location = win.location;
export var gc = win['gc'] ? () => win['gc']() : (): any => null;
export var performance = win['performance'] ? win['performance'] : null;
export const Event = win['Event'];
export const MouseEvent = win['MouseEvent'];
export const KeyboardEvent = win['KeyboardEvent'];
export const EventTarget = win['EventTarget'];
export const History = win['History'];
export const Location = win['Location'];
export const EventListener = win['EventListener'];
export const document = win.document;
export const location = win.location;
export const gc = win.gc ? () => win.gc() : (): any => null;
export const performance = win.performance ? win.performance : null;
export const Event = win.Event;
export const MouseEvent = win.MouseEvent;
export const KeyboardEvent = win.KeyboardEvent;
export const EventTarget = win.EventTarget;
export const History = win.History;
export const Location = win.Location;
export const EventListener = win.EventListener;
2 changes: 2 additions & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
"baseUrl": "./",
"outDir": "./temp/out-tsc",
"sourceMap": true,
"strict": true,
"strictPropertyInitialization": false,
"declaration": false,
"moduleResolution": "node",
"emitDecoratorMetadata": true,
Expand Down