From 53cf6735648f216ce3c8c5fe94f62cf078a63f2c Mon Sep 17 00:00:00 2001 From: Jongsun Suh <34228073+MajorLift@users.noreply.github.com> Date: Fri, 13 Oct 2023 14:14:24 -0700 Subject: [PATCH] Replace `as T[]` assertions with `?? []` - `as` assertions intended to exclude an empty/nullable type can be replaced by a nullish coalescing operator converting nullable values into an acceptable empty value that doesn't pollute the variable's type signature. - TODO: document and expound in https://github.com/MetaMask/contributor-docs/issues/47 --- src/changelog.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/changelog.ts b/src/changelog.ts index f04addc..bdbd8a1 100644 --- a/src/changelog.ts +++ b/src/changelog.ts @@ -89,7 +89,7 @@ function stringifyRelease( const categorizedChanges = orderedChangeCategories .filter((category) => categories[category]) .map((category) => { - const changes = categories[category] as string[]; + const changes = categories[category] ?? []; return stringifyCategory(category, changes); }) .join('\n\n'); @@ -386,8 +386,8 @@ export default class Changelog { for (const category of Object.keys(unreleasedChanges) as ChangeCategory[]) { if (releaseChanges[category]) { releaseChanges[category] = [ - ...(unreleasedChanges[category] as string[]), - ...(releaseChanges[category] as string[]), + ...(unreleasedChanges[category] ?? []), + ...(releaseChanges[category] ?? []), ]; } else { releaseChanges[category] = unreleasedChanges[category];