fix(router): Update types for TypeScript nullability support

This reverts commit ea8ffc9841.
This commit is contained in:
Miško Hevery
2017-04-17 11:13:13 -07:00
committed by Tobias Bosch
parent ec028b8109
commit bc431888f3
26 changed files with 230 additions and 223 deletions

View File

@ -45,7 +45,7 @@ export function flatten<T>(arr: T[][]): T[] {
return Array.prototype.concat.apply([], arr);
}
export function last<T>(a: T[]): T {
export function last<T>(a: T[]): T|null {
return a.length > 0 ? a[a.length - 1] : null;
}

View File

@ -17,7 +17,7 @@ export class Tree<T> {
/**
* @internal
*/
parent(t: T): T {
parent(t: T): T|null {
const p = this.pathFromRoot(t);
return p.length > 1 ? p[p.length - 2] : null;
}
@ -33,7 +33,7 @@ export class Tree<T> {
/**
* @internal
*/
firstChild(t: T): T {
firstChild(t: T): T|null {
const n = findNode(t, this._root);
return n && n.children.length > 0 ? n.children[0].value : null;
}
@ -55,7 +55,7 @@ export class Tree<T> {
pathFromRoot(t: T): T[] { return findPath(t, this._root, []).map(s => s.value); }
}
function findNode<T>(expected: T, c: TreeNode<T>): TreeNode<T> {
function findNode<T>(expected: T, c: TreeNode<T>): TreeNode<T>|null {
if (expected === c.value) return c;
for (const cc of c.children) {
const r = findNode(expected, cc);