-
-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(partial): improve deep partial type to ensure compilation without…
… errors when passing default values to create mock and create mock list Partial deep source https://github.com/sindresorhus/type-fest/blob/master/source/partial-deep.d.ts
- Loading branch information
Showing
5 changed files
with
53 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,11 @@ | ||
import { NoTransformerError } from './errors/no-transformer.error'; | ||
import { DeepPartial } from './partial/deepPartial'; | ||
import { PartialDeep } from './partial/partial'; | ||
|
||
export function createMockList<T extends object>( | ||
// eslint-disable-next-line @typescript-eslint/no-unused-vars | ||
quantity: number, | ||
// eslint-disable-next-line @typescript-eslint/no-unused-vars | ||
iterator?: (index: number) => DeepPartial<T> | ||
iterator?: (index: number) => PartialDeep<T> | ||
): T[] { | ||
throw new Error(NoTransformerError); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
import { NoTransformerError } from './errors/no-transformer.error'; | ||
import { DeepPartial } from './partial/deepPartial'; | ||
import { PartialDeep } from './partial/partial'; | ||
|
||
// eslint-disable-next-line @typescript-eslint/no-unused-vars | ||
export function createMock<T extends object>(values?: DeepPartial<T>): T { | ||
export function createMock<T extends object>(values?: PartialDeep<T>): T { | ||
throw new Error(NoTransformerError); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
type Primitive = null | undefined | string | number | boolean | symbol | bigint; | ||
|
||
export type PartialDeep<T> = T extends Primitive | ||
? Partial<T> | ||
: T extends Map<infer KeyType, infer ValueType> | ||
? PartialMapDeep<KeyType, ValueType> | ||
: T extends Set<infer ItemType> | ||
? PartialSetDeep<ItemType> | ||
: T extends ReadonlyMap<infer KeyType, infer ValueType> | ||
? PartialReadonlyMapDeep<KeyType, ValueType> | ||
: T extends ReadonlySet<infer ItemType> | ||
? PartialReadonlySetDeep<ItemType> // eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
: T extends (...args: any[]) => unknown | ||
? T | undefined | ||
: T extends object | ||
? PartialObjectDeep<T> | ||
: unknown; | ||
|
||
/** | ||
Same as `PartialDeep`, but accepts only `Map`s and as inputs. Internal helper for `PartialDeep`. | ||
*/ | ||
interface PartialMapDeep<KeyType, ValueType> | ||
extends Map<PartialDeep<KeyType>, PartialDeep<ValueType>> {} | ||
|
||
/** | ||
Same as `PartialDeep`, but accepts only `Set`s as inputs. Internal helper for `PartialDeep`. | ||
*/ | ||
interface PartialSetDeep<T> extends Set<PartialDeep<T>> {} | ||
|
||
/** | ||
Same as `PartialDeep`, but accepts only `ReadonlyMap`s as inputs. Internal helper for `PartialDeep`. | ||
*/ | ||
interface PartialReadonlyMapDeep<KeyType, ValueType> | ||
extends ReadonlyMap<PartialDeep<KeyType>, PartialDeep<ValueType>> {} | ||
|
||
/** | ||
Same as `PartialDeep`, but accepts only `ReadonlySet`s as inputs. Internal helper for `PartialDeep`. | ||
*/ | ||
interface PartialReadonlySetDeep<T> extends ReadonlySet<PartialDeep<T>> {} | ||
|
||
/** | ||
Same as `PartialDeep`, but accepts only `object`s as inputs. Internal helper for `PartialDeep`. | ||
*/ | ||
type PartialObjectDeep<ObjectType extends object> = { | ||
[KeyType in keyof ObjectType]?: PartialDeep<ObjectType[KeyType]>; | ||
}; |