Giter Site home page Giter Site logo

Comments (22)

Shinigami92 avatar Shinigami92 commented on May 23, 2024 4

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.

damienwebdev avatar damienwebdev commented on May 23, 2024 4

read: weeks.

from faker.

micalevisk avatar micalevisk commented on May 23, 2024 4

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.

Shinigami92 avatar Shinigami92 commented on May 23, 2024 3
// 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.

Shinigami92 avatar Shinigami92 commented on May 23, 2024 2

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.

Shinigami92 avatar Shinigami92 commented on May 23, 2024 1

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.

MohdImran001 avatar MohdImran001 commented on May 23, 2024 1

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.

damienwebdev avatar damienwebdev commented on May 23, 2024 1

Given the workaround here: #9 (comment) I'm closing this issue.

from faker.

nicolasrouanne avatar nicolasrouanne commented on May 23, 2024 1

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.

Shinigami92 avatar Shinigami92 commented on May 23, 2024 1

@SametSahin10 Please try import faker from "@faker-js/faker" 😉

Could also be that you need "esModuleInterop": true in tsconfig.json

from faker.

SametSahin10 avatar SametSahin10 commented on May 23, 2024 1

@SametSahin10 Please try import faker from "@faker-js/faker" wink

Could also be that you need "esModuleInterop": true in tsconfig.json

I've added "esModuleInterop": true into tsconfig.json and it worked. 👍

from faker.

nick-krantz avatar nick-krantz commented on May 23, 2024

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.

Shinigami92 avatar Shinigami92 commented on May 23, 2024

The rewrite to TS could take some days

from faker.

nick-krantz avatar nick-krantz commented on May 23, 2024

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.

sramam avatar sramam commented on May 23, 2024

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.

MilosPaunovic avatar MilosPaunovic commented on May 23, 2024

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.

SametSahin10 avatar SametSahin10 commented on May 23, 2024

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.

Shinigami92 avatar Shinigami92 commented on May 23, 2024

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.

SametSahin10 avatar SametSahin10 commented on May 23, 2024

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.

SametSahin10 avatar SametSahin10 commented on May 23, 2024

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.

Shinigami92 avatar Shinigami92 commented on May 23, 2024

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.

SametSahin10 avatar SametSahin10 commented on May 23, 2024

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

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.