-
-
Notifications
You must be signed in to change notification settings - Fork 944
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
Feat: Add typescript types for @faker-js/faker #9
Comments
I'd be interested in contributing to getting types going for the project. Based on the discussion in #14, I think the intention is to add the types to DefinitelyTyped? Is that correct? |
For now please create a file in your repo with content: // faker.d.ts
declare module '@faker-js/faker' {
import faker from 'faker';
export default faker;
} and then just use the |
The rewrite to TS could take some days |
read: weeks. |
Oh I must have misunderstood, I thought there would be an intermediate state where types would come before the TS rewrite.
I believe it |
It works! I tested this im my own repo at work! |
Can't this be actually included in the current repo? Happy to submit a PR is that seems like an acceptable band-aid. |
Hello @MohdImran001, You were willing to help with types on |
This will not work, cause the current versions <=5.5.3 are already released and not touched by us except the package name. |
Thanks, for tagging me here @MilosPaunovic. 😃. As far as I have understood, @Shinigami92 is working on all the Typescript related things in #72. @Shinigami92 Please let me know, how can I get started. I have joined the discord server. |
Given the workaround here: #9 (comment) I'm closing this issue. |
FWIW in order to use named imports, I had to make a slightly different export from the // faker.d.ts
declare module '@faker-js/faker' {
import faker from 'faker';
export = faker;
} Using it as named imports // some test file
import { datatype, date, hacker } from '@faker-js/faker'; This was inspired by how faker is exported from DefinitelyTyped |
another way is using TS path aliases like: {
"compilerOptions": {
"paths": {
"faker/*": ["@faker-js/faker/*"],
"faker": ["@faker-js/faker"]
}
}
} thus you don't need to change anything besides the |
Does the location of the faker.d.ts file matter? Where should we put the file? |
Please note that you can already switch to v6.0.0-alpha.3 with native TS support 🙌 |
Oh, really? I spent some time trying to figure out how I can link the faker.d.ts with the @types/faker package. Maybe the README file could be updated to remove the Typescript Support section or there could be a mention of the fact that TS support is available in the latest version. |
Already planed 😉 |
The index.d.ts file handles the linking, right? Back then, we needed to create the faker.d.ts file because the index.d.ts did not exist. I'm currently learning how declaration files work in TS. @Shinigami92 |
Yes it does, sadly we have currently for some an issue in the |
Is the issue about importing? Cause I cannot import faker with:
I get "Cannot find module or its type declarations" and "Unable to resolve path to module faker". |
@SametSahin10 Please try Could also be that you need |
I've added |
No description provided.
The text was updated successfully, but these errors were encountered: