From 74cefa848c2aa50484f465e019194daef77f5791 Mon Sep 17 00:00:00 2001 From: Jake Bailey <5341706+jakebailey@users.noreply.github.com> Date: Fri, 26 Jul 2024 10:08:40 -0700 Subject: [PATCH] Tighten signature of append (#59426) --- src/compiler/core.ts | 25 ++++++++----------- src/server/session.ts | 2 +- .../tsbuildWatch/watchEnvironment.ts | 2 +- 3 files changed, 12 insertions(+), 17 deletions(-) diff --git a/src/compiler/core.ts b/src/compiler/core.ts index e2238766ee5..fc692f1a65d 100644 --- a/src/compiler/core.ts +++ b/src/compiler/core.ts @@ -396,7 +396,7 @@ export function flatten(array: T[][] | readonly (T | readonly T[] | undefined * * @internal */ -export function flatMap(array: readonly T[] | undefined, mapfn: (x: T, i: number) => U | readonly U[] | undefined): readonly U[] { +export function flatMap(array: readonly T[] | undefined, mapfn: (x: T, i: number) => U | readonly U[] | undefined): readonly U[] { let result: U[] | undefined; if (array !== undefined) { for (let i = 0; i < array.length; i++) { @@ -917,18 +917,13 @@ export function relativeComplement(arrayA: T[] | undefined, arrayB: T[] | und * * @internal */ -export function append[number] | undefined>(to: TArray, value: TValue): [undefined, undefined] extends [TArray, TValue] ? TArray : NonNullable[number][]; +export function append(to: T[], value: T | undefined): T[]; /** @internal */ -export function append(to: T[], value: T | undefined): T[]; +export function append(to: T[] | undefined, value: T): T[]; /** @internal */ -export function append(to: T[] | undefined, value: T): T[]; -/** @internal */ -export function append(to: T[] | undefined, value: T | undefined): T[] | undefined; -/** @internal */ -export function append(to: T[], value: T | undefined): void; -/** @internal */ -export function append(to: T[] | undefined, value: T | undefined): T[] | undefined { - if (value === undefined) return to as T[]; +export function append(to: T[] | undefined, value: T | undefined): T[] | undefined; +export function append(to: T[] | undefined, value: T | undefined): T[] | undefined { + if (value === undefined) return to; if (to === undefined) return [value]; to.push(value); return to; @@ -948,13 +943,13 @@ export function append(to: T[] | undefined, value: T | undefined): T[] | unde * * @internal */ -export function combine(xs: T[] | undefined, ys: T[] | undefined): T[] | undefined; +export function combine(xs: T[] | undefined, ys: T[] | undefined): T[] | undefined; /** @internal */ -export function combine(xs: T | readonly T[] | undefined, ys: T | readonly T[] | undefined): T | readonly T[] | undefined; +export function combine(xs: T | readonly T[] | undefined, ys: T | readonly T[] | undefined): T | readonly T[] | undefined; /** @internal */ -export function combine(xs: T | T[] | undefined, ys: T | T[] | undefined): T | T[] | undefined; +export function combine(xs: T | T[] | undefined, ys: T | T[] | undefined): T | T[] | undefined; /** @internal */ -export function combine(xs: T | T[] | undefined, ys: T | T[] | undefined) { +export function combine(xs: T | T[] | undefined, ys: T | T[] | undefined) { if (xs === undefined) return ys; if (ys === undefined) return xs; if (isArray(xs)) return isArray(ys) ? concatenate(xs, ys) : append(xs, ys); diff --git a/src/server/session.ts b/src/server/session.ts index 40640d052be..fd0ed26586d 100644 --- a/src/server/session.ts +++ b/src/server/session.ts @@ -486,7 +486,7 @@ type Projects = readonly Project[] | { /** * This helper function processes a list of projects and return the concatenated, sortd and deduplicated output of processing each project. */ -function combineProjectOutput( +function combineProjectOutput( defaultValue: T, getValue: (path: Path) => T, projects: Projects, diff --git a/src/testRunner/unittests/tsbuildWatch/watchEnvironment.ts b/src/testRunner/unittests/tsbuildWatch/watchEnvironment.ts index ad830d0d92a..d8c76df25df 100644 --- a/src/testRunner/unittests/tsbuildWatch/watchEnvironment.ts +++ b/src/testRunner/unittests/tsbuildWatch/watchEnvironment.ts @@ -80,7 +80,7 @@ describe("unittests:: tsbuildWatch:: watchEnvironment:: tsbuild:: watchMode:: wi watchOrSolution: solutionBuilder, }); - function flatArray(arr: T[][]): readonly T[] { + function flatArray(arr: T[][]): readonly T[] { return ts.flatMap(arr, ts.identity); } function pkgs(cb: (index: number) => T): T[] {