Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Call could still return null when using fallbackLocale #80

Closed
bravo-kernel opened this issue Feb 27, 2023 · 3 comments
Closed

Call could still return null when using fallbackLocale #80

bravo-kernel opened this issue Feb 27, 2023 · 3 comments
Labels
enhancement New feature or request

Comments

@bravo-kernel
Copy link

Unsure if this is related to this module but I was expecting that defining a fallbackLocale would always return a string. I am trying to do this:

import { getUserLocale } from "get-user-locale"

const locale = getUserLocale({
  fallbackLocale: "en",
  useFallbackLocale: true
})

if(["in", "hi-IN"].includes(locale){
  // do something
}

However, include complains with below type error about possible null so I am guessing it is not detected:

Argument of type 'string | null' is not assignable to parameter of type 'string'.
  Type 'null' is not assignable to type 'string'.

Any pointers on how to solve this, if possible at all?

@bravo-kernel
Copy link
Author

It seems I can just add an exclamation mark to locale to get rid of the type error.

if(["in", "hi-IN"].includes(locale!){
  // do something
}

Feel free to close unless you think this should be handled by the module.

@wojtekmaj wojtekmaj added the enhancement New feature or request label Mar 8, 2023
@wojtekmaj
Copy link
Owner

Unless useFallbackLocale was specifically set to false, indeed there's no possibility of getting null back. I fixed that by adding function overloads :)

@bravo-kernel
Copy link
Author

Ah, perfect. Much appreciated ❤️

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants