From 3a4ce0035feeee051a82b7ddcad22f8bc12be46d Mon Sep 17 00:00:00 2001 From: Evan Hahn Date: Mon, 22 Apr 2024 15:13:17 +0000 Subject: [PATCH] chore: fix type error in local slice This is a types-only change and should have no impact on functionality. `usePersistedLocale` had a type error because `getLocales()[0]` might be undefined. However, the docs for `getLocales()` say that we are "guaranteed" to have at least one element, so we can use a non-null assertion. --- src/frontend/hooks/persistedState/usePersistedLocale.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/frontend/hooks/persistedState/usePersistedLocale.ts b/src/frontend/hooks/persistedState/usePersistedLocale.ts index 2d4c2cad0..c541ceaa2 100644 --- a/src/frontend/hooks/persistedState/usePersistedLocale.ts +++ b/src/frontend/hooks/persistedState/usePersistedLocale.ts @@ -9,7 +9,10 @@ type LocaleSlice = { }; const localeSlice: StateCreator = (set, get) => ({ - locale: getSupportedLocale(getLocales()[0].languageTag) || 'en', + // We can use this non-null assertion with `getLocales()` because, according + // to [the docs][1], the result is "guaranteed to contain at least 1 element." + // [1]: https://github.com/expo/expo/blob/5585320eec9271038cd7c672b4cf9f0e945ca658/packages/expo-localization/src/Localization.ts#L123 + locale: getSupportedLocale(getLocales()[0]!.languageTag) || 'en', setLocale: newlocale => set({locale: newlocale}), });