Skip to content

Commit b804988

Browse files
authored
Fix optional attributes in a parent factory causing all attributes to be required in a child factory (#39)
1 parent 6c8f611 commit b804988

File tree

3 files changed

+8
-5
lines changed

3 files changed

+8
-5
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "typical-data",
3-
"version": "0.4.1",
3+
"version": "0.4.2",
44
"description": "Test data factory",
55
"homepage": "https://github.com/davidtkramer/typical-data",
66
"main": "./dist/index.js",

src/__tests__/factory.test.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,7 @@ describe('DSL', () => {
265265
interface BaseContact {
266266
id: number;
267267
phone: string;
268+
meta?: string;
268269
}
269270
const baseFactory = createFactory((factory) =>
270271
factory
@@ -275,6 +276,7 @@ describe('DSL', () => {
275276
id: 1,
276277
phone: ({ transientParams }) =>
277278
`(${transientParams.areaCode}) 123-4567`,
279+
meta: undefined,
278280
})
279281
.trait('invalidPhone', { phone: 'asdf' })
280282
.trait('withCountryCode', (trait) =>

src/types.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,11 @@ export type TransientParamsForTraits<
99
/**
1010
* Converts a union of values to an intersection of values.
1111
*/
12-
export type Intersect<U> = {
13-
[K in GetKeys<U>]: U extends Record<K, infer T> ? T : never;
14-
};
15-
type GetKeys<U> = U extends Record<infer K, any> ? K : never;
12+
export type Intersect<T> = (T extends any ? (x: T) => any : never) extends (
13+
x: infer R
14+
) => any
15+
? R
16+
: never;
1617

1718
/**
1819
* Makes optional the keys on Child that also exist on Parent.

0 commit comments

Comments
 (0)