fix(platform-browser): Update types for TypeScript nullability support
Closes #15898
This commit is contained in:

committed by
Tobias Bosch

parent
01d93f3af8
commit
728c9d0632
@ -49,6 +49,6 @@ export class By {
|
||||
* {@example platform-browser/dom/debug/ts/by/by.ts region='by_directive'}
|
||||
*/
|
||||
static directive(type: Type<any>): Predicate<DebugElement> {
|
||||
return (debugElement) => debugElement.providerTokens.indexOf(type) !== -1;
|
||||
return (debugElement) => debugElement.providerTokens !.indexOf(type) !== -1;
|
||||
}
|
||||
}
|
||||
|
@ -22,7 +22,7 @@ const CORE_TOKENS_GLOBAL_NAME = 'ng.coreTokens';
|
||||
* null if the given native element does not have an Angular view associated
|
||||
* with it.
|
||||
*/
|
||||
export function inspectNativeElement(element: any): core.DebugNode {
|
||||
export function inspectNativeElement(element: any): core.DebugNode|null {
|
||||
return core.getDebugNode(element);
|
||||
}
|
||||
|
||||
|
@ -8,7 +8,7 @@
|
||||
|
||||
import {Type} from '@angular/core';
|
||||
|
||||
let _DOM: DomAdapter = null;
|
||||
let _DOM: DomAdapter = null !;
|
||||
|
||||
export function getDOM() {
|
||||
return _DOM;
|
||||
@ -32,7 +32,7 @@ export function setRootDomAdapter(adapter: DomAdapter) {
|
||||
* can introduce XSS risks.
|
||||
*/
|
||||
export abstract class DomAdapter {
|
||||
public resourceLoaderType: Type<any> = null;
|
||||
public resourceLoaderType: Type<any> = null !;
|
||||
abstract hasProperty(element: any, name: string): boolean;
|
||||
abstract setProperty(el: Element, name: string, value: any): any;
|
||||
abstract getProperty(el: Element, name: string): any;
|
||||
@ -68,12 +68,12 @@ export abstract class DomAdapter {
|
||||
abstract getTemplateContent(el: any): any;
|
||||
abstract getOuterHTML(el: any): string;
|
||||
abstract nodeName(node: any): string;
|
||||
abstract nodeValue(node: any): string;
|
||||
abstract nodeValue(node: any): string|null;
|
||||
abstract type(node: any): string;
|
||||
abstract content(node: any): any;
|
||||
abstract firstChild(el: any): Node;
|
||||
abstract nextSibling(el: any): Node;
|
||||
abstract parentElement(el: any): Node;
|
||||
abstract firstChild(el: any): Node|null;
|
||||
abstract nextSibling(el: any): Node|null;
|
||||
abstract parentElement(el: any): Node|null;
|
||||
abstract childNodes(el: any): Node[];
|
||||
abstract childNodesAsList(el: any): Node[];
|
||||
abstract clearNodes(el: any): any;
|
||||
@ -85,7 +85,7 @@ export abstract class DomAdapter {
|
||||
abstract insertAllBefore(parent: any, ref: any, nodes: any): any;
|
||||
abstract insertAfter(parent: any, el: any, node: any): any;
|
||||
abstract setInnerHTML(el: any, value: any): any;
|
||||
abstract getText(el: any): string;
|
||||
abstract getText(el: any): string|null;
|
||||
abstract setText(el: any, value: string): any;
|
||||
abstract getValue(el: any): string;
|
||||
abstract setValue(el: any, value: string): any;
|
||||
@ -117,7 +117,7 @@ export abstract class DomAdapter {
|
||||
abstract attributeMap(element: any): Map<string, string>;
|
||||
abstract hasAttribute(element: any, attribute: string): boolean;
|
||||
abstract hasAttributeNS(element: any, ns: string, attribute: string): boolean;
|
||||
abstract getAttribute(element: any, attribute: string): string;
|
||||
abstract getAttribute(element: any, attribute: string): string|null;
|
||||
abstract getAttributeNS(element: any, ns: string, attribute: string): string;
|
||||
abstract setAttribute(element: any, name: string, value: string): any;
|
||||
abstract setAttributeNS(element: any, ns: string, name: string, value: string): any;
|
||||
@ -145,12 +145,12 @@ export abstract class DomAdapter {
|
||||
abstract getGlobalEventTarget(doc: Document, target: string): any;
|
||||
abstract getHistory(): History;
|
||||
abstract getLocation(): Location;
|
||||
abstract getBaseHref(doc: Document): string;
|
||||
abstract getBaseHref(doc: Document): string|null;
|
||||
abstract resetBaseElement(): void;
|
||||
abstract getUserAgent(): string;
|
||||
abstract setData(element: any, name: string, value: string): any;
|
||||
abstract getComputedStyle(element: any): any;
|
||||
abstract getData(element: any, name: string): string;
|
||||
abstract getData(element: any, name: string): string|null;
|
||||
abstract setGlobalVar(name: string, value: any): any;
|
||||
abstract supportsWebAnimation(): boolean;
|
||||
abstract performanceNow(): number;
|
||||
@ -159,6 +159,6 @@ export abstract class DomAdapter {
|
||||
abstract supportsAnimation(): boolean;
|
||||
|
||||
abstract supportsCookies(): boolean;
|
||||
abstract getCookie(name: string): string;
|
||||
abstract getCookie(name: string): string|null;
|
||||
abstract setCookie(name: string, value: string): any;
|
||||
}
|
||||
|
@ -67,7 +67,7 @@ export class DomRendererFactory2 implements RendererFactory2 {
|
||||
this.defaultRenderer = new DefaultDomRenderer2(eventManager);
|
||||
};
|
||||
|
||||
createRenderer(element: any, type: RendererType2): Renderer2 {
|
||||
createRenderer(element: any, type: RendererType2|null): Renderer2 {
|
||||
if (!element || !type) {
|
||||
return this.defaultRenderer;
|
||||
}
|
||||
|
@ -59,8 +59,8 @@ const EVENT_NAMES = {
|
||||
export const HAMMER_GESTURE_CONFIG = new InjectionToken<HammerGestureConfig>('HammerGestureConfig');
|
||||
|
||||
export interface HammerInstance {
|
||||
on(eventName: string, callback: Function): void;
|
||||
off(eventName: string, callback: Function): void;
|
||||
on(eventName: string, callback?: Function): void;
|
||||
off(eventName: string, callback?: Function): void;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -31,7 +31,7 @@ export class KeyEventsPlugin extends EventManagerPlugin {
|
||||
supports(eventName: string): boolean { return KeyEventsPlugin.parseEventName(eventName) != null; }
|
||||
|
||||
addEventListener(element: HTMLElement, eventName: string, handler: Function): Function {
|
||||
const parsedEvent = KeyEventsPlugin.parseEventName(eventName);
|
||||
const parsedEvent = KeyEventsPlugin.parseEventName(eventName) !;
|
||||
|
||||
const outsideHandler =
|
||||
KeyEventsPlugin.eventCallback(parsedEvent['fullKey'], handler, this.manager.getZone());
|
||||
@ -41,7 +41,7 @@ export class KeyEventsPlugin extends EventManagerPlugin {
|
||||
});
|
||||
}
|
||||
|
||||
static parseEventName(eventName: string): {[key: string]: string} {
|
||||
static parseEventName(eventName: string): {[key: string]: string}|null {
|
||||
const parts: string[] = eventName.toLowerCase().split('.');
|
||||
|
||||
const domEventName = parts.shift();
|
||||
@ -49,7 +49,7 @@ export class KeyEventsPlugin extends EventManagerPlugin {
|
||||
return null;
|
||||
}
|
||||
|
||||
const key = KeyEventsPlugin._normalizeKey(parts.pop());
|
||||
const key = KeyEventsPlugin._normalizeKey(parts.pop() !);
|
||||
|
||||
let fullKey = '';
|
||||
MODIFIER_KEYS.forEach(modifierName => {
|
||||
|
Reference in New Issue
Block a user