Comments (22)
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 @types/faker
from faker.
read: weeks.
from faker.
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 tsconfig
file.
from faker.
// faker.d.ts declare module '@faker-js/faker' { import faker from 'faker'; export default faker; }
It works! I tested this im my own repo at work!
Nothing wrong with them, cause until now we did not change anything according to that.
from faker.
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 😉
But we decide it to leave as is for now, until v6.0.0 is fully released
from faker.
Can't this be actually included in the current repo? That way, it'll get fixed when it'll get fixed and we won't have to back out this change from a 10^6 downstream modules.
Happy to submit a PR is that seems like an acceptable band-aid.
This will not work, cause the current versions <=5.5.3 are already released and not touched by us except the package name.
But I already working on TS migration at all #72, but sadly I'm a human and not a AI, so this could take a week or so
from faker.
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.
from faker.
Given the workaround here: #9 (comment) I'm closing this issue.
from faker.
FWIW in order to use named imports, I had to make a slightly different export from the .d.ts
file than the proposed solution:
// 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
from faker.
@SametSahin10 Please try import faker from "@faker-js/faker"
😉
Could also be that you need "esModuleInterop": true
in tsconfig.json
from faker.
@SametSahin10 Please try
import faker from "@faker-js/faker"
winkCould also be that you need
"esModuleInterop": true
in tsconfig.json
I've added "esModuleInterop": true
into tsconfig.json and it worked. 👍
from faker.
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?
from faker.
The rewrite to TS could take some days
from faker.
Oh I must have misunderstood, I thought there would be an intermediate state where types would come before the TS rewrite.
read: weeks.
I believe it
from faker.
Can't this be actually included in the current repo?
That way, it'll get fixed when it'll get fixed and we won't have to back out this change from a 10^6 downstream modules.
Happy to submit a PR is that seems like an acceptable band-aid.
from faker.
Hello @MohdImran001,
You were willing to help with types on community-faker
, https://github.com/MilosPaunovic/community-faker/issues/3, but, for the benefit of the OpenSource, we are moving the official community-driven fork here, so, are you willing to help out here, as well?
from faker.
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
@types/faker
Does the location of the faker.d.ts file matter? Where should we put the file?
from faker.
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 🙌
from faker.
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 raised_hands
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.
from faker.
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
from faker.
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 -alpha.3
because we shipped the index.ts
next to index.d.ts
, but this will be already fixed in -alpha.4
from faker.
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
-alpha.3
because we shipped theindex.ts
next toindex.d.ts
, but this will be already fixed in-alpha.4
Is the issue about importing? Cause I cannot import faker with:
import * as faker from "faker"
I get "Cannot find module or its type declarations" and "Unable to resolve path to module faker".
from faker.
Related Issues (20)
- faker.helpers.objectKey returns wrong type HOT 3
- Discuss boundaries of type-less JavaScript support HOT 10
- Make separate export for simpleFaker HOT 7
- [ERROR] The entry point "mock/table.ts.timestamp-1710847630001.mjs" cannot be marked as external HOT 4
- [v9 MAINTENANCE] - Please Read
- Re-add simplified implementation of helpers.unique HOT 6
- Email addresses are unknown on fakerHE in Hebrew HOT 1
- Random CI test failure in date.birthdate for specific age HOT 2
- Speed up normalisation code HOT 8
- Release Checklist v9.0.0-alpha.0 HOT 1
- create icon on simple-icons HOT 32
- Localization lastName is not working HOT 2
- Phone numbers should support special numbers HOT 1
- Check capitisation of ex_MX/color/human
- Add v9.fakerjs.dev
- [Website] Change Navigation Behaviour HOT 4
- Generate Planet names HOT 9
- More varied product descriptions HOT 2
- Can't use Faker with k6 HOT 15
- Vehicle data is very US-centric HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from faker.