refactor(platform-browser): compatibility with typescript strict flag (#30993)

As part of FW-1265, the `@angular/platform-browser` package is made compatible
with the TypeScript `--strict` flag. Read more about the strict flag [here](https://www.typescriptlang.org/docs/handbook/compiler-options.html)

PR Close #30993
This commit is contained in:
Paul Gschwendtner 2019-06-13 20:14:00 +02:00 committed by Miško Hevery
parent 5bd12c5aa1
commit 18f0c2f1d4
2 changed files with 10 additions and 8 deletions

View File

@ -63,9 +63,9 @@ const _chromeNumKeyPadMap = {
'\x90': 'NumLock'
};
const nodeContains: (a: any, b: any) => boolean = (() => {
const nodeContains: (this: Node, other: Node) => boolean = (() => {
if (global['Node']) {
return global['Node'].prototype.contains || function(node: any) {
return global['Node'].prototype.contains || function(this: Node, node: any) {
return !!(this.compareDocumentPosition(node) & 16);
};
}

View File

@ -61,7 +61,7 @@ interface TaskData {
// a global listener to handle all dom event,
// so we do not need to create a closure every time
const globalListener = function(event: Event) {
const globalListener = function(this: any, event: Event) {
const symbolName = symbolNames[event.type];
if (!symbolName) {
return;
@ -123,15 +123,17 @@ export class DomEventsPlugin extends EventManagerPlugin {
}
const delegate = (Event.prototype as any)[stopMethodSymbol] =
Event.prototype.stopImmediatePropagation;
Event.prototype.stopImmediatePropagation = function() {
Event.prototype.stopImmediatePropagation = function(this: any) {
if (this) {
this[stopSymbol] = true;
}
// should call native delegate in case
// in some environment part of the application
// will not use the patched Event
delegate && delegate.apply(this, arguments);
// We should call native delegate in case in some environment part of
// the application will not use the patched Event. Also we cast the
// "arguments" to any since "stopImmediatePropagation" technically does not
// accept any arguments, but we don't know what developers pass through the
// function and we want to not break these calls.
delegate && delegate.apply(this, arguments as any);
};
}