From f12fbf67f91188ccbe62884e7de6ffddfe19ff7e Mon Sep 17 00:00:00 2001 From: chilam <39334548+ch1lam@users.noreply.github.com> Date: Sun, 15 May 2022 19:30:43 +0800 Subject: docs(docs/guide): Add typescript support in the guide (#947) --- docs/guide/index.md | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) (limited to 'docs/guide') diff --git a/docs/guide/index.md b/docs/guide/index.md index 18bd257c..f83966b7 100644 --- a/docs/guide/index.md +++ b/docs/guide/index.md @@ -90,6 +90,38 @@ It is highly recommended to use version tags when importing libraries in Deno, e - https://cdn.jsdelivr.net/npm/@faker-js/faker +### TypeScript Support + +Since version `v6+` there is native TypeScript support. + +In order to have faker working properly, you need to check if these `compilerOptions` are set correctly in your `tsconfig` file: + +```json +{ + "compilerOptions": { + "esModuleInterop": true, + "moduleResolution": "Node" + } +} +``` + +And then simply import it like everything else: + +```ts +import { faker } from '@faker-js/faker'; +``` + +If you want for whatever reason the versions prior to `v6`, +you can use `@types/faker` and rebind the declarations to the `@faker-js/faker` package with a `faker.d.ts` file in your e.g. src folder. + +```ts +// faker.d.ts +declare module '@faker-js/faker' { + import faker from 'faker'; + export default faker; +} +``` + ## Community If you have questions or need help, reach out to the community via [Discord](https://chat.fakerjs.dev) and [GitHub Discussions](https://github.com/faker-js/faker/discussions). -- cgit v1.2.3