Skip to content

Commit 27ddd4a

Browse files
fix(form-core): preserve FieldWithValue name string type (#2466)
* fix(form-core): preserve FieldWithValue name string type * ci: apply automated fixes and generate docs --------- Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
1 parent 2b4fc5c commit 27ddd4a

3 files changed

Lines changed: 33 additions & 1 deletion

File tree

‎.changeset/dark-suits-itch.md‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@tanstack/form-core': patch
3+
---
4+
5+
Fix FieldWithValue name type to preserve string typing

‎packages/form-core/src/types.public.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ export type OneOrMany<TValue> = TValue | Array<TValue>
5050
* @typeParam TFieldValue - The value type preserved across field reads and update methods.
5151
*/
5252
export type FieldWithValue<TFieldValue> = FieldApi<
53-
any,
53+
string,
5454
TFieldValue,
5555
any,
5656
any,
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import { describe, expectTypeOf, it } from 'vitest'
2+
import type { FieldWithValue } from '../src'
3+
4+
describe('FieldWithValue', () => {
5+
it('should preserve string typing for field name', () => {
6+
const field = null as unknown as FieldWithValue<boolean>
7+
8+
expectTypeOf<typeof field.name>().toEqualTypeOf<string>()
9+
expectTypeOf<typeof field.value>().toEqualTypeOf<boolean>()
10+
11+
const validName: string = field.name
12+
13+
// @ts-expect-error Field name must not be a number
14+
const invalidName: number = field.name
15+
16+
// @ts-expect-error Field name does not have Number methods
17+
field.name.toFixed()
18+
19+
// @ts-expect-error Boolean field must not accept a string
20+
field.handleChange('not a boolean')
21+
22+
field.handleChange(true)
23+
24+
void validName
25+
void invalidName
26+
})
27+
})

0 commit comments

Comments
 (0)