Skip to content

Commit 2e7e935

Browse files
mprobstalxhub
authored andcommitted
fix(common): fix a Closure compilation issue.
Closure Compiler cannot infer that the swtich statement is exhaustive, which causes it to complain that the method does not always return a value. Work around the problem by throwing an exception in the default case, and using the `: never` type to ensure the code is unreachable.
1 parent b89e7c2 commit 2e7e935

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

packages/common/src/i18n/format_date.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,13 @@ function getDateTranslation(
270270
return getLocaleDayPeriods(locale, form, <TranslationWidth>width)[currentHours < 12 ? 0 : 1];
271271
case TranslationType.Eras:
272272
return getLocaleEraNames(locale, <TranslationWidth>width)[date.getFullYear() <= 0 ? 0 : 1];
273+
default:
274+
// This default case is not needed by TypeScript compiler, as the switch is exhaustive.
275+
// However Closure Compiler does not understand that and reports an error in typed mode.
276+
// The `throw new Error` below works around the problem, and the unexpected: never variable
277+
// makes sure tsc still checks this code is unreachable.
278+
const unexpected: never = name;
279+
throw new Error(`unexpected translation type ${unexpected}`);
273280
}
274281
}
275282

0 commit comments

Comments
 (0)