Skip to content

Commit 8b7e81e

Browse files
committed
Improve Types: remove slow types from codebase
1 parent 34b8322 commit 8b7e81e

File tree

2 files changed

+5
-4
lines changed

2 files changed

+5
-4
lines changed

deno.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@functions/mock",
33
"description": "Lightweight utility to generate realistic mock data for tests fast.",
4-
"version": "1.0.1",
4+
"version": "1.1.0",
55
"license": "MIT",
66
"exports":"./mod.ts",
77
"tasks": {

utils/get-mocks-with.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ const uniGenerator = {
55
id: faker.string.uuid,
66
owner_id: faker.string.uuid,
77
name: faker.person.firstName,
8-
age: () => faker.number.int({ min: 18, max: 99 }),
8+
age: (): number => faker.number.int({ min: 18, max: 99 }),
99
username: faker.internet.username,
1010
email: faker.internet.email,
1111
avatar: faker.image.avatar,
@@ -18,13 +18,14 @@ const uniGenerator = {
1818

1919
type Generator = typeof uniGenerator
2020
type GenKeys = keyof Generator
21-
type GetGenCallableFn = <T extends GenKeys>( props: Array<T>) => {[K in T]: Generator[K]}
21+
type GetGenCallableFn = <T extends GenKeys>( props: Array<T> ) => {[K in T]: Generator[K]}
2222

2323

2424
const getGenerator: GetGenCallableFn = (props) => {
2525
return props.reduce((acc,curr) => ({...acc, [curr]:uniGenerator[curr]}), Object.create(null) )
2626
}
2727

28+
type GetMocksCallableFn = <T extends GenKeys>(props: Array<T>) => (num:number) => Array<{[K in T]: ReturnType<Generator[K]>}>
2829
/**
2930
* Generate the random function to create your mock object/s based on a list of properties
3031
* It preserves type safety and autocompletion
@@ -34,7 +35,7 @@ const getGenerator: GetGenCallableFn = (props) => {
3435
* const createRandomUsers = generateMocksFrom(props)
3536
* console.log( createRandomUsers(3) )
3637
*/
37-
export const getMocksWith = <T extends GenKeys>(properties: Array<T>) => getMocksFromGenerator( getGenerator(properties) )
38+
export const getMocksWith: GetMocksCallableFn = (properties) => getMocksFromGenerator(getGenerator(properties))
3839

3940

4041

0 commit comments

Comments
 (0)