Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/dark-suits-itch.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@tanstack/form-core': patch
---

Fix FieldWithValue name type to preserve string typing
2 changes: 1 addition & 1 deletion packages/form-core/src/types.public.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export type OneOrMany<TValue> = TValue | Array<TValue>
* @typeParam TFieldValue - The value type preserved across field reads and update methods.
*/
export type FieldWithValue<TFieldValue> = FieldApi<
any,
string,
TFieldValue,
any,
any,
Expand Down
27 changes: 27 additions & 0 deletions packages/form-core/tests/FieldWithValue.test-d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { describe, expectTypeOf, it } from 'vitest'
import type { FieldWithValue } from '../src'

describe('FieldWithValue', () => {
it('should preserve string typing for field name', () => {
const field = null as unknown as FieldWithValue<boolean>

expectTypeOf<typeof field.name>().toEqualTypeOf<string>()
expectTypeOf<typeof field.value>().toEqualTypeOf<boolean>()

const validName: string = field.name

// @ts-expect-error Field name must not be a number
const invalidName: number = field.name

// @ts-expect-error Field name does not have Number methods
field.name.toFixed()

// @ts-expect-error Boolean field must not accept a string
field.handleChange('not a boolean')

field.handleChange(true)

void validName
void invalidName
})
})
Loading