From 18f0c2f1d4a7901e4b1becc9be4859058c1f2a5e Mon Sep 17 00:00:00 2001 From: Paul Gschwendtner Date: Thu, 13 Jun 2019 20:14:00 +0200 Subject: [PATCH] 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 --- .../src/browser/browser_adapter.ts | 4 ++-- .../platform-browser/src/dom/events/dom_events.ts | 14 ++++++++------ 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/packages/platform-browser/src/browser/browser_adapter.ts b/packages/platform-browser/src/browser/browser_adapter.ts index d40cf891eb..5747047fbb 100644 --- a/packages/platform-browser/src/browser/browser_adapter.ts +++ b/packages/platform-browser/src/browser/browser_adapter.ts @@ -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); }; } diff --git a/packages/platform-browser/src/dom/events/dom_events.ts b/packages/platform-browser/src/dom/events/dom_events.ts index 2d3045eb15..051a63d339 100644 --- a/packages/platform-browser/src/dom/events/dom_events.ts +++ b/packages/platform-browser/src/dom/events/dom_events.ts @@ -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); }; }