No typescript declaration files for locales
IanVS opened this issue · 7 comments
In the published module, there are no typescript definitions for the locales. This is a problem because I am unable to use the side-effect import of 'minifaker/dist/locales/en'
to set a locale, for some reason. It only seems to work if I follow this pattern:
import { addLocale, word, WordType } from 'minifaker';
import en from 'minifaker/dist/locales/en';
addLocale('en', en);
But then I get a typescript error.
Typescript for locales are not generated because you don't have to use addLocale
.
import { word, WordType } from 'minifaker'
import 'minifaker/dist/locales/en'
word()
Here is where it's added when importing the locale
minifaker/src/locales/en/index.ts
Line 71 in 242926e
The addLocale
function is if you want to create your own custom locale.
What is the Typescript error?
I don't get a typescript error if I use the approach you mention, with the side-effect import. I get an error from word
that a locale has not been set.
I'll try to make a reproduction to share.
Thanks! Here's a reproduction of what I see when using the side-effect import:
Thanks a lot for the repro! I was able to fix it.
I had to seperate both syntax in there own unique folder dist/esm
, dist/cjs
. The exact problem was that the addLocale
while using side-effect import was resolving to the cjs file and the word
function was using the esm file. They don't share the same locales :S
Plus, I added the NPM exports for locales. You don't have to use dist
anymore :)
import 'minifaker/locales/en'
Lines 8 to 28 in 6664ed5
Awesome, thanks! I'll give the new version a shot tonight or tomorrow.