In one of my config files config.js file, I have:
module.exports = {
locales: ['en', 'fr']
}
In my library, I try to import the config.js file and turn it into a typescript liberal type like so:
import config from "config.js"
const tempDefaultLocales = [...config.locales] as const
export type Language = typeof tempDefaultLocales[number]
But the type of Language is string and not "en" | "fr"
If I don't import and just hard type it, the as const works. Example:
const locales = ["en","fr"] as const
type Language = typeof locales[number]
Gives me the correct type of "en" | "fr"
Any idea how I can make this work without changing my config file to ts or hardcoding it?
Here is a sandbox: https://codesandbox.io/s/awesome-swirles-ij4qsg?file=/src/App.tsx
PS: I can't change the config to ts because the config file is actually next.config.js and they don't allow us to change it and I want to avoid having 2 config files to set my languages.
Thanks

next.config.jsfrom NextJS. I'm trying to just have one file to update my language settings, if no choice, I would need to define and update the language in 2 files for internationalization to work. I checked a request on github to supporttsfor the config file but they don't plan on doing it.