piernik
piernik

Reputation: 3657

How to use faker.js in typescript?

As in topic. I cannot handle it :/ I've installed npm i faker and also npm i @types/faker --save-dev

my IDE found fakerStatic.name.findName() but browser not recognizes fakerStatic.

import 'faker'; does not help.

Upvotes: 22

Views: 35479

Answers (2)

Michael S.
Michael S.

Reputation: 711

The documentation now says:

import { faker } from '@faker-js/faker'

If it is to be localized data, the desired locale can also be attached.

import { faker } from '@faker-js/faker/locale/de'

Upvotes: 6

Saravana
Saravana

Reputation: 40702

You have to import it like:

import * as faker from 'faker';

And use it like:

faker.name.findName()

Upvotes: 56

Related Questions