@formisch/react 0.4.1 → 0.4.3

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.
package/dist/index.d.ts CHANGED
@@ -188,23 +188,27 @@ type InternalFieldStore = InternalArrayStore | InternalObjectStore | InternalVal
188
188
  /**
189
189
  * Checks if a type is `any`.
190
190
  */
191
- type IsAny<Type> = 0 extends 1 & Type ? true : false;
191
+ type IsAny<T> = 0 extends 1 & T ? true : false;
192
192
  /**
193
193
  * Checks if a type is `never`.
194
194
  */
195
- type IsNever<Type> = [Type] extends [never] ? true : false;
195
+ type IsNever<T> = [T] extends [never] ? true : false;
196
196
  /**
197
197
  * Constructs a type that is maybe a promise.
198
198
  */
199
- type MaybePromise<TValue> = TValue | Promise<TValue>;
199
+ type MaybePromise<T> = T | Promise<T>;
200
200
  /**
201
201
  * Makes all properties deeply optional.
202
202
  */
203
- type DeepPartial<TValue> = TValue extends Record<PropertyKey, unknown> | readonly unknown[] ? { [Key in keyof TValue]?: DeepPartial<TValue[Key]> | undefined } : TValue | undefined;
203
+ type DeepPartial<TValue> = TValue extends Record<PropertyKey, unknown> | readonly unknown[] ? { [TKey in keyof TValue]?: DeepPartial<TValue[TKey]> | undefined } : TValue | undefined;
204
204
  /**
205
205
  * Makes all value properties optional.
206
+ *
207
+ * Hint: For dynamic arrays, only plain objects and nested arrays have their
208
+ * values made optional. Primitives and class instances are kept as-is to avoid
209
+ * types like `(string | undefined)[]`.
206
210
  */
207
- type PartialValues<TValue> = TValue extends Record<PropertyKey, unknown> | readonly unknown[] ? { [Key in keyof TValue]: PartialValues<TValue[Key]> } : TValue | undefined;
211
+ type PartialValues<TValue> = TValue extends readonly (infer TItem)[] ? number extends TValue["length"] ? (TItem extends Record<PropertyKey, unknown> | readonly unknown[] ? { [TKey in keyof TItem]: PartialValues<TItem[TKey]> } : TItem)[] : { [TKey in keyof TValue]: PartialValues<TValue[TKey]> } : TValue extends Record<PropertyKey, unknown> ? { [TKey in keyof TValue]: PartialValues<TValue[TKey]> } : TValue | undefined;
208
212
  //#endregion
209
213
  //#region src/values.d.ts
210
214
  /**
@@ -245,7 +249,7 @@ interface InternalFormStore<TSchema extends Schema = Schema> extends InternalObj
245
249
  /**
246
250
  * The element of the form.
247
251
  */
248
- element?: HTMLFormElement;
252
+ element?: HTMLFormElement | undefined;
249
253
  /**
250
254
  * The number of active validators.
251
255
  */
@@ -321,7 +325,7 @@ type KeyOf<TValue> = IsAny<TValue> extends true ? never : TValue extends readonl
321
325
  * properties that do not exist in all union options are not accessible
322
326
  * and result in "any" when accessed.
323
327
  */
324
- type MergeUnion<T> = { [K in KeyOf<T>]: T extends Record<K, infer V> ? V : never };
328
+ type MergeUnion<TValue> = { [TKey in KeyOf<TValue>]: TValue extends Record<TKey, infer TItem> ? TItem : never };
325
329
  /**
326
330
  * Lazily evaluates only the first valid path segment based on the given value.
327
331
  */
@@ -652,7 +656,7 @@ interface ResetFieldConfig<TSchema extends Schema, TFieldPath extends RequiredPa
652
656
  * The new initial input to reset the field to. If provided, replaces the
653
657
  * field's initial input.
654
658
  */
655
- readonly initialInput?: DeepPartial<PathValue<v.InferInput<TSchema>, TFieldPath>>;
659
+ readonly initialInput?: DeepPartial<PathValue<v.InferInput<TSchema>, TFieldPath>> | undefined;
656
660
  }
657
661
  /**
658
662
  * Resets a specific field or the entire form to its initial state. Provides
package/dist/index.js CHANGED
@@ -116,10 +116,10 @@ function untrack(fn) {
116
116
  */
117
117
  function initializeFieldStore(internalFieldStore, schema, initialInput, path, nullish = false) {
118
118
  if (framework === "qwik" && schema.type === "lazy" || schema.type === "object_with_rest" || schema.type === "record" || schema.type === "tuple_with_rest" || schema.type === "promise") throw new Error(`"${schema.type}" schema is not supported`);
119
- else if (schema.type === "lazy") initializeFieldStore(internalFieldStore, schema.getter(void 0), initialInput, path);
119
+ else if (schema.type === "lazy") initializeFieldStore(internalFieldStore, schema.getter(void 0), initialInput, path, nullish);
120
120
  else if (schema.type === "exact_optional" || schema.type === "nullable" || schema.type === "nullish" || schema.type === "optional" || schema.type === "undefinedable") initializeFieldStore(internalFieldStore, schema.wrapped, initialInput === void 0 ? v.getDefault(schema) : initialInput, path, true);
121
121
  else if (schema.type === "non_nullable" || schema.type === "non_nullish" || schema.type === "non_optional") initializeFieldStore(internalFieldStore, schema.wrapped, initialInput, path);
122
- else if (schema.type === "intersect" || schema.type === "union" || schema.type === "variant") for (const schemaOption of schema.options) initializeFieldStore(internalFieldStore, schemaOption, initialInput, path);
122
+ else if (schema.type === "intersect" || schema.type === "union" || schema.type === "variant") for (const schemaOption of schema.options) initializeFieldStore(internalFieldStore, schemaOption, initialInput, path, nullish);
123
123
  else {
124
124
  internalFieldStore.schema = schema;
125
125
  internalFieldStore.name = JSON.stringify(path);
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@formisch/react",
3
3
  "description": "The modular and type-safe form library for React",
4
- "version": "0.4.1",
4
+ "version": "0.4.3",
5
5
  "license": "MIT",
6
6
  "author": "Fabian Hiller",
7
7
  "homepage": "https://formisch.dev",
@@ -46,7 +46,7 @@
46
46
  "tsdown": "^0.16.8",
47
47
  "typescript": "~5.9.3",
48
48
  "vite": "^7.2.4",
49
- "@formisch/core": "0.6.1",
49
+ "@formisch/core": "0.6.3",
50
50
  "@formisch/eslint-config": "0.1.0",
51
51
  "@formisch/methods": "0.7.0"
52
52
  },