@tanstack/form-core 0.45.0 → 0.47.0
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/cjs/FieldApi.cjs.map +1 -1
- package/dist/cjs/FieldApi.d.cts +1 -1
- package/dist/cjs/FormApi.cjs +29 -14
- package/dist/cjs/FormApi.cjs.map +1 -1
- package/dist/cjs/FormApi.d.cts +4 -0
- package/dist/cjs/mergeForm.cjs.map +1 -1
- package/dist/cjs/mergeForm.d.cts +0 -1
- package/dist/cjs/util-types.d.cts +19 -17
- package/dist/esm/FieldApi.d.ts +1 -1
- package/dist/esm/FieldApi.js.map +1 -1
- package/dist/esm/FormApi.d.ts +4 -0
- package/dist/esm/FormApi.js +29 -14
- package/dist/esm/FormApi.js.map +1 -1
- package/dist/esm/mergeForm.d.ts +0 -1
- package/dist/esm/mergeForm.js.map +1 -1
- package/dist/esm/util-types.d.ts +19 -17
- package/package.json +1 -1
- package/src/FieldApi.ts +1 -6
- package/src/FormApi.ts +57 -24
- package/src/mergeForm.ts +0 -1
- package/src/util-types.ts +44 -42
- package/dist/cjs/FormApi.test-d.d.cts +0 -1
- package/dist/esm/FormApi.test-d.d.ts +0 -1
- package/src/FormApi.test-d.ts +0 -31
package/src/mergeForm.ts
CHANGED
package/src/util-types.ts
CHANGED
|
@@ -1,13 +1,7 @@
|
|
|
1
|
-
type Nullable<T> = T | null
|
|
2
|
-
type IsNullable<T> = [null] extends [T] ? true : false
|
|
3
|
-
|
|
4
|
-
export type UnwrapOneLevelOfArray<T> = T extends (infer U)[] ? U : T
|
|
5
|
-
|
|
6
1
|
/**
|
|
7
2
|
* @private
|
|
8
3
|
*/
|
|
9
|
-
export type
|
|
10
|
-
Required<Pick<T, K>>
|
|
4
|
+
export type UnwrapOneLevelOfArray<T> = T extends (infer U)[] ? U : T
|
|
11
5
|
|
|
12
6
|
type Narrowable = string | number | bigint | boolean
|
|
13
7
|
|
|
@@ -18,23 +12,12 @@ type NarrowRaw<A> =
|
|
|
18
12
|
[K in keyof A]: A[K] extends Function ? A[K] : NarrowRaw<A[K]>
|
|
19
13
|
}
|
|
20
14
|
|
|
21
|
-
/**
|
|
22
|
-
* @private
|
|
23
|
-
*/
|
|
24
|
-
export type NoInfer<T> = [T][T extends any ? 0 : never]
|
|
25
|
-
|
|
26
|
-
/**
|
|
27
|
-
* @private
|
|
28
|
-
*/
|
|
29
|
-
export type Narrow<A> = Try<A, [], NarrowRaw<A>>
|
|
30
|
-
|
|
31
15
|
type Try<A1, A2, Catch = never> = A1 extends A2 ? A1 : Catch
|
|
32
16
|
|
|
33
17
|
/**
|
|
34
|
-
* Hack to get TypeScript to show simplified types in error messages
|
|
35
18
|
* @private
|
|
36
19
|
*/
|
|
37
|
-
export type
|
|
20
|
+
export type Narrow<A> = Try<A, [], NarrowRaw<A>>
|
|
38
21
|
|
|
39
22
|
type ComputeRange<
|
|
40
23
|
N extends number,
|
|
@@ -105,6 +88,16 @@ type PrefixFromDepth<
|
|
|
105
88
|
TDepth extends any[],
|
|
106
89
|
> = TDepth['length'] extends 0 ? T : `.${T}`
|
|
107
90
|
|
|
91
|
+
// Hack changing Typescript's default get behavior in order to work with union objects
|
|
92
|
+
type Get<T, K extends string> = T extends { [Key in K]: infer V }
|
|
93
|
+
? V
|
|
94
|
+
: T extends { [Key in K]?: infer W }
|
|
95
|
+
? W | undefined
|
|
96
|
+
: never
|
|
97
|
+
|
|
98
|
+
type ApplyNull<T> = null extends T ? null : never
|
|
99
|
+
type ApplyUndefined<T> = undefined extends T ? undefined : never
|
|
100
|
+
|
|
108
101
|
/**
|
|
109
102
|
* Infer the type of a deeply nested property within an object or an array.
|
|
110
103
|
*/
|
|
@@ -113,36 +106,45 @@ export type DeepValue<
|
|
|
113
106
|
TValue,
|
|
114
107
|
// A string representing the path of the property we're trying to access
|
|
115
108
|
TAccessor,
|
|
116
|
-
|
|
117
|
-
> =
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
109
|
+
// Depth for preventing infinite recursion
|
|
110
|
+
TDepth extends ReadonlyArray<any> = [],
|
|
111
|
+
> = unknown extends TValue // If TValue is any it will recurse forever, this terminates the recursion
|
|
112
|
+
? TValue
|
|
113
|
+
: TDepth['length'] extends 10
|
|
114
|
+
? unknown
|
|
121
115
|
: // Check if we're looking for the property in an array
|
|
122
116
|
TValue extends ReadonlyArray<any>
|
|
123
117
|
? TAccessor extends `[${infer TBrackets}].${infer TAfter}`
|
|
124
118
|
? /*
|
|
125
119
|
Extract the first element from the accessor path (`TBrackets`)
|
|
126
120
|
and recursively call `DeepValue` with it
|
|
127
|
-
|
|
128
|
-
DeepValue<
|
|
121
|
+
*/
|
|
122
|
+
DeepValue<
|
|
123
|
+
DeepValue<TValue, TBrackets, [...TDepth, any]>,
|
|
124
|
+
TAfter,
|
|
125
|
+
[...TDepth, any]
|
|
126
|
+
>
|
|
129
127
|
: TAccessor extends `[${infer TBrackets}]`
|
|
130
|
-
? DeepValue<TValue, TBrackets>
|
|
128
|
+
? DeepValue<TValue, TBrackets, [...TDepth, any]>
|
|
131
129
|
: TAccessor extends keyof TValue
|
|
132
130
|
? TValue[TAccessor]
|
|
133
131
|
: TValue[TAccessor & number]
|
|
134
|
-
:
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
132
|
+
: TAccessor extends `${infer TBefore}[${infer TEverythingElse}`
|
|
133
|
+
? DeepValue<
|
|
134
|
+
DeepValue<TValue, TBefore, [...TDepth, any]>,
|
|
135
|
+
`[${TEverythingElse}`,
|
|
136
|
+
[...TDepth, any]
|
|
137
|
+
>
|
|
138
|
+
: TAccessor extends `[${infer TBrackets}]`
|
|
139
|
+
? DeepValue<TValue, TBrackets, [...TDepth, any]>
|
|
140
|
+
: TAccessor extends `${infer TBefore}.${infer TAfter}`
|
|
141
|
+
? DeepValue<
|
|
142
|
+
DeepValue<TValue, TBefore, [...TDepth, any]>,
|
|
143
|
+
TAfter,
|
|
144
|
+
[...TDepth, any]
|
|
145
|
+
>
|
|
146
|
+
: TAccessor extends string
|
|
147
|
+
?
|
|
148
|
+
| Get<TValue, TAccessor>
|
|
149
|
+
| (ApplyNull<TValue> | ApplyUndefined<TValue>)
|
|
150
|
+
: never
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
package/src/FormApi.test-d.ts
DELETED
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
import { assertType, it } from 'vitest'
|
|
2
|
-
import { FormApi } from '../src/index'
|
|
3
|
-
|
|
4
|
-
it('should type handleSubmit as never when onSubmitMeta is not passed', () => {
|
|
5
|
-
const form = new FormApi({
|
|
6
|
-
defaultValues: {
|
|
7
|
-
name: 'test',
|
|
8
|
-
},
|
|
9
|
-
} as const)
|
|
10
|
-
|
|
11
|
-
assertType<() => Promise<void>>(form.handleSubmit)
|
|
12
|
-
})
|
|
13
|
-
|
|
14
|
-
type OnSubmitMeta = {
|
|
15
|
-
group: string
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
it('should type handleChange correctly', () => {
|
|
19
|
-
const form = new FormApi({
|
|
20
|
-
defaultValues: {
|
|
21
|
-
name: 'test',
|
|
22
|
-
},
|
|
23
|
-
onSubmitMeta: {} as OnSubmitMeta,
|
|
24
|
-
} as const)
|
|
25
|
-
|
|
26
|
-
form.handleSubmit({ group: 'track' })
|
|
27
|
-
|
|
28
|
-
assertType<(submitMeta: { group: string }) => Promise<void>>(
|
|
29
|
-
form.handleSubmit,
|
|
30
|
-
)
|
|
31
|
-
})
|