Closed allezxandre closed 1 year ago
On a side note, Typescript will still complain about imports of actual locales in the form of import en from '$locales/en'
as the $locales/*
module is not defined.
@allezxandre maybe there's a way of letting typescript know that $locales/<code>
where code is any language code of the list of know language codes is valid.
In any case, this is a great improvement.
@allezxandre maybe there's a way of letting typescript know that
$locales/<code>
where code is any language code of the list of know language codes is valid.
Yes, setting something like so:
interface Locale {
[key: string]: string;
}
declare module "$locales/*" {
const locale: Locale;
export default locale;
}
would work, but it would accept any language, including imports of random string like $locales/123R4ND0M
.
There might be a better solution but alas I'm not experienced enough in Typescript module declarations to know 😕
I don't see it very prioritary because most often than not apps should be using registerAll
, unless they have a good reason not to (and since languages can be lazy loaded, there are very few good reasons)
A top-level export in
index.d.ts
was preventing Typescript from using typings for$locales
when imported from a Typescript project.This PR fixes this by putting the export in a module declaration.