Skip to content
This repository has been archived by the owner on Oct 30, 2022. It is now read-only.

Commit

Permalink
Fix TypeScript types
Browse files Browse the repository at this point in the history
  • Loading branch information
k4m4 committed Dec 8, 2019
1 parent 5a4effa commit afded0a
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 28 deletions.
52 changes: 25 additions & 27 deletions index.d.ts
Original file line number Diff line number Diff line change
@@ -1,42 +1,40 @@
declare namespace jaymock {
type ExtensionName = string | {[key: string]: Function};
type Functions = {[key: string]: Function};
type Instance = {template: jaymock.Template, functions: jaymock.Functions}
interface Template {
[key: string]: string | number | Template;
}
interface Populated {
[key: string]: unknown | Array<Populated> | Populated;
}
interface Method {
/**
Populates the template object with fake data.
@param template - A [`template`](https://github.com/unmock/jaymock#template) object to populate.
@returns An `object` populated with fake data.
*/
populate(template: jaymock.Template): jaymock.Populated;
}

/**
Adds a custom data generation function that can be called in the `populate` `template` object using the value of its `name`.
@param name - A `string` used to refer to the `body` function.
@param body - A `function` that can be referred to in the `template` object.
*/
extend(name: jaymock.ExtensionName, body?: Function): void;
declare function jaymock(): {
/**
Populates the template object with fake data.
@param template - A [`template`](https://github.com/unmock/jaymock#template) object to populate.
@returns An `object` populated with fake data.
*/
populate(template: jaymock.Template): jaymock.Populated;

/**
Sets `Faker.js`'s language locale.
@param locale - `Faker.js` locale.
*/
setFakerLocale(locale: string): void;
/**
Adds a custom data generation function that can be called in the `populate` `template` object using the value of its `name`.
@param name - A `string` used to refer to the `body` function.
@param body - A `function` that can be referred to in the `template` object.
*/
extend(name: jaymock.ExtensionName, body?: Function): void;

/**
Sets `Faker.js`'s randomness seed.
@param seed - `Faker.js` randomness seed.
*/
setFakerSeed(seed: number): void;
}
}
/**
Sets `Faker.js`'s language locale.
@param locale - `Faker.js` locale.
*/
setFakerLocale(locale: string): void;

declare function jaymock(): jaymock.Instance & jaymock.Method;
/**
Sets `Faker.js`'s randomness seed.
@param seed - `Faker.js` randomness seed.
*/
setFakerSeed(seed: number): void;
};

export = jaymock;
1 change: 0 additions & 1 deletion index.test-d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import jaymock = require('.');

const jm = jaymock();

expectType<jaymock.Instance & jaymock.Method>(jm);
expectType<jaymock.Populated>(jm.populate({
name: 'fake({{name.lastName}}, {{name.firstName}} {{name.suffix}})',
ssn: 'chance.ssn',
Expand Down

0 comments on commit afded0a

Please sign in to comment.