@zayne-labs/toolkit-type-helpers 0.8.56 → 0.8.58

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/dist/esm/index.d.ts +19 -15
  2. package/package.json +4 -1
@@ -44,29 +44,33 @@ type Writeable<TObject, TVariant extends WriteableVariantUnion = "shallow"> = TO
44
44
  -readonly [Key in keyof TObject]: TVariant extends "shallow" ? TObject[Key] : TVariant extends "deep" ? TObject[Key] extends object ? Writeable<TObject[Key], TVariant> : TObject[Key] : never;
45
45
  } : TObject;
46
46
 
47
- type AllowOnlyFirst<TFirstType, TSecondType, TExclusionValue = never> = Prettify<TFirstType & Partial<Record<keyof Omit<TSecondType, keyof TFirstType>, TExclusionValue>>>;
48
- type AllowOnlyFirstRequired<TFirstType, TSecondType, TExclusionValue = never> = Prettify<TFirstType & Record<keyof Omit<TSecondType, keyof TFirstType>, TExclusionValue>>;
47
+ /**
48
+ * Type utility that takes two types and allows only the properties of the first type. The properties of the second will be disallowed (typed as `never` by default or a custom message).
49
+ *
50
+ * @template TFirstType The first type. Properties of this type will be required.
51
+ * @template TSecondType The second type. Properties of this type will be disallowed.
52
+ * @template TErrorMessages An object of custom messages to display on the properties of the second type that are disallowed.
53
+ */
54
+ type AllowOnlyFirst<TFirstType, TSecondType, TErrorMessages extends Record<string, unknown> = never> = Prettify<TFirstType & {
55
+ [Key in keyof Omit<TSecondType, keyof TFirstType>]?: Key extends keyof TErrorMessages ? TErrorMessages[Key] : never;
56
+ }>;
57
+ /**
58
+ * Merges all types in an array of types into one type.
59
+ *
60
+ * @template TArrayOfTypes Array of types to merge
61
+ * @template TAccumulator Accumulator for the resulting merged type
62
+ */
49
63
  type MergeTypes<TArrayOfTypes extends unknown[], TAccumulator = NonNullable<unknown>> = TArrayOfTypes extends [infer TFirstType, ...infer TRest] ? MergeTypes<TRest, TAccumulator & TFirstType> : TAccumulator;
50
64
  /**
51
65
  * Type utility that extracts discriminated properties from a union of types.
52
66
  * Takes an array of types and returns a union of types where each type has unique properties.
53
67
  *
54
68
  * @template TArrayOfTypes Array of types to process
55
- * @template TExclusionValue Value to exclude from the resulting union
69
+ * @template TErrorMessages An object of custom messages to display on the properties that are disallowed.
56
70
  * @template TAccumulator Accumulator for the resulting union
57
71
  * @template TMergedProperties Merged properties from all types
58
72
  */
59
- type UnionDiscriminator<TArrayOfTypes extends unknown[], TExclusionValue = never, TAccumulator = never, TMergedProperties = MergeTypes<TArrayOfTypes>> = TArrayOfTypes extends [infer TFirstType, ...infer TRest] ? UnionDiscriminator<TRest, TExclusionValue, TAccumulator | AllowOnlyFirst<TFirstType, TMergedProperties, TExclusionValue>, TMergedProperties> : TAccumulator;
60
- /**
61
- * Type utility that extracts discriminated properties from a union of types.
62
- * Takes an array of types and returns a union of types where each type has unique properties.
63
- *
64
- * @template TArrayOfTypes - Array of types to process
65
- * @template TExclusionValue - Value to exclude from the resulting union
66
- * @template TAccumulator - Accumulator for the resulting union
67
- * @template TMergedProperties - Merged properties from all types
68
- */
69
- type UnionDiscriminatorRequired<TArrayOfTypes extends unknown[], TExclusionValue = never, TAccumulator = never, TMergedProperties = MergeTypes<TArrayOfTypes>> = TArrayOfTypes extends [infer TFirstType, ...infer TRest] ? UnionDiscriminatorRequired<TRest, TExclusionValue, TAccumulator | AllowOnlyFirstRequired<TFirstType, TMergedProperties, TExclusionValue>, TMergedProperties> : TAccumulator;
73
+ type UnionDiscriminator<TArrayOfTypes extends unknown[], TErrorMessages extends Record<string, unknown> = never, TAccumulator = never, TMergedProperties = MergeTypes<TArrayOfTypes>> = TArrayOfTypes extends [infer TFirstType, ...infer TRest] ? UnionDiscriminator<TRest, TErrorMessages, TAccumulator | AllowOnlyFirst<TFirstType, TMergedProperties, TErrorMessages>, TMergedProperties> : TAccumulator;
70
74
  type ExtractUnion<TObject, TVariant extends "keys" | "values" = "values"> = TObject extends Array<infer TUnion> | ReadonlyArray<infer TUnion> | Set<infer TUnion> ? TUnion : TObject extends Record<infer TKeys, infer TValues> ? TVariant extends "keys" ? TKeys : Prettify<Writeable<TValues, "deep">> : never;
71
75
 
72
76
  declare const isString: (value: unknown) => value is string;
@@ -105,4 +109,4 @@ declare const assert: AssertFn;
105
109
 
106
110
  declare const defineEnum: <TVariant extends WriteableVariantUnion = "shallow", const TValue = NonNullable<unknown>>(value: TValue) => Prettify<Writeable<TValue, TVariant>>;
107
111
 
108
- export { type AnyAsyncFunction, type AnyFunction, type AnyNumber, type AnyObject, type AnyString, AssertionError, type CallbackFn, type ExtractUnion, type LiteralUnion, type NonEmptyArray, type NonFalsy, type Prettify, type PrettyOmit, type PrettyPick, type SelectorFn, type UnionDiscriminator, type UnionDiscriminatorRequired, type UnknownObject, type UnknownObjectWithAnyKey, type UnmaskType, type Writeable, type WriteableVariantUnion, assert, assertDefined, assertENV, defineEnum, hasObjectPrototype, isArray, isAsyncFunction, isBoolean, isFile, isFormData, isFunction, isIterable, isNumber, isObject, isObjectAndNotArray, isPlainObject, isString, isSymbol };
112
+ export { type AnyAsyncFunction, type AnyFunction, type AnyNumber, type AnyObject, type AnyString, AssertionError, type CallbackFn, type ExtractUnion, type LiteralUnion, type NonEmptyArray, type NonFalsy, type Prettify, type PrettyOmit, type PrettyPick, type SelectorFn, type UnionDiscriminator, type UnknownObject, type UnknownObjectWithAnyKey, type UnmaskType, type Writeable, type WriteableVariantUnion, assert, assertDefined, assertENV, defineEnum, hasObjectPrototype, isArray, isAsyncFunction, isBoolean, isFile, isFormData, isFunction, isIterable, isNumber, isObject, isObjectAndNotArray, isPlainObject, isString, isSymbol };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@zayne-labs/toolkit-type-helpers",
3
3
  "type": "module",
4
- "version": "0.8.56",
4
+ "version": "0.8.58",
5
5
  "description": "A collection of utility functions, types and composables used by my other projects. Nothing too fancy but can be useful.",
6
6
  "author": "Ryan Zayne",
7
7
  "license": "MIT",
@@ -67,6 +67,9 @@
67
67
  "build:test": "concurrently --prefix-colors \"yellow.bold,#7da4f8.bold,magenta\" --names PUBLINT,TSUP 'pnpm:lint:publint' 'pnpm:build:dev'",
68
68
  "dev": "pnpm build:dev --watch",
69
69
  "lint:attw": "attw --pack . --ignore-rules=cjs-resolves-to-esm",
70
+ "lint:eslint": "eslint . --max-warnings 0",
71
+ "lint:eslint:interactive": "pnpx eslint-interactive@latest . --max-warnings 0 --fix",
72
+ "lint:format": "prettier --write .",
70
73
  "lint:publint": "publint --strict .",
71
74
  "lint:size": "size-limit",
72
75
  "lint:type-check": "tsc --pretty -p tsconfig.json",