1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109
|
=== tests/cases/compiler/inferenceDoesNotAddUndefinedOrNull.ts ===
interface NodeArray<T extends Node> extends ReadonlyArray<T> {}
interface Node {
forEachChild<T>(cbNode: (node: Node) => T | undefined, cbNodeArray?: (nodes: NodeArray<Node>) => T | undefined): T | undefined;
>forEachChild : <T>(cbNode: (node: Node) => T | undefined, cbNodeArray?: ((nodes: NodeArray<Node>) => T | undefined) | undefined) => T | undefined
>cbNode : (node: Node) => T | undefined
>node : Node
>cbNodeArray : ((nodes: NodeArray<Node>) => T | undefined) | undefined
>nodes : NodeArray<Node>
}
declare function toArray<T>(value: T | T[]): T[];
>toArray : { <T>(value: T | T[]): T[]; <T>(value: T | readonly T[]): readonly T[]; }
>value : T | T[]
declare function toArray<T>(value: T | readonly T[]): readonly T[];
>toArray : { <T>(value: T | T[]): T[]; <T>(value: T | readonly T[]): readonly T[]; }
>value : T | readonly T[]
function flatMapChildren<T>(node: Node, cb: (child: Node) => readonly T[] | T | undefined): readonly T[] {
>flatMapChildren : <T>(node: Node, cb: (child: Node) => readonly T[] | T | undefined) => readonly T[]
>node : Node
>cb : (child: Node) => readonly T[] | T | undefined
>child : Node
const result: T[] = [];
>result : T[]
>[] : never[]
node.forEachChild(child => {
>node.forEachChild(child => { const value = cb(child); if (value !== undefined) { result.push(...toArray(value)); } }) : void | undefined
>node.forEachChild : <T>(cbNode: (node: Node) => T | undefined, cbNodeArray?: ((nodes: NodeArray<Node>) => T | undefined) | undefined) => T | undefined
>node : Node
>forEachChild : <T>(cbNode: (node: Node) => T | undefined, cbNodeArray?: ((nodes: NodeArray<Node>) => T | undefined) | undefined) => T | undefined
>child => { const value = cb(child); if (value !== undefined) { result.push(...toArray(value)); } } : (child: Node) => void
>child : Node
const value = cb(child);
>value : T | readonly T[] | undefined
>cb(child) : T | readonly T[] | undefined
>cb : (child: Node) => T | readonly T[] | undefined
>child : Node
if (value !== undefined) {
>value !== undefined : boolean
>value : T | readonly T[] | undefined
>undefined : undefined
result.push(...toArray(value));
>result.push(...toArray(value)) : number
>result.push : (...items: T[]) => number
>result : T[]
>push : (...items: T[]) => number
>...toArray(value) : T
>toArray(value) : readonly T[]
>toArray : { <T>(value: T | T[]): T[]; <T>(value: T | readonly T[]): readonly T[]; }
>value : readonly T[] | (T & ({} | null))
}
});
return result;
>result : T[]
}
function flatMapChildren2<T>(node: Node, cb: (child: Node) => readonly T[] | T | null): readonly T[] {
>flatMapChildren2 : <T>(node: Node, cb: (child: Node) => readonly T[] | T | null) => readonly T[]
>node : Node
>cb : (child: Node) => readonly T[] | T | null
>child : Node
>null : null
const result: T[] = [];
>result : T[]
>[] : never[]
node.forEachChild(child => {
>node.forEachChild(child => { const value = cb(child); if (value !== null) { result.push(...toArray(value)); } }) : void | undefined
>node.forEachChild : <T>(cbNode: (node: Node) => T | undefined, cbNodeArray?: ((nodes: NodeArray<Node>) => T | undefined) | undefined) => T | undefined
>node : Node
>forEachChild : <T>(cbNode: (node: Node) => T | undefined, cbNodeArray?: ((nodes: NodeArray<Node>) => T | undefined) | undefined) => T | undefined
>child => { const value = cb(child); if (value !== null) { result.push(...toArray(value)); } } : (child: Node) => void
>child : Node
const value = cb(child);
>value : T | readonly T[] | null
>cb(child) : T | readonly T[] | null
>cb : (child: Node) => T | readonly T[] | null
>child : Node
if (value !== null) {
>value !== null : boolean
>value : T | readonly T[] | null
>null : null
result.push(...toArray(value));
>result.push(...toArray(value)) : number
>result.push : (...items: T[]) => number
>result : T[]
>push : (...items: T[]) => number
>...toArray(value) : T
>toArray(value) : readonly T[]
>toArray : { <T>(value: T | T[]): T[]; <T>(value: T | readonly T[]): readonly T[]; }
>value : readonly T[] | (T & ({} | undefined))
}
});
return result;
>result : T[]
}
|