Describe the bug
When exporting an inferred formOptions(...) value that includes listeners, TypeScript fails during declaration emit with TS4023.
The inferred exported type references TanStack Form's internal FormListenersPropsField type from @tanstack/form-core/dist/esm/FormApi. Since that type is not publicly exported/nameable, TypeScript cannot serialize the exported formOptions(...) value into a .d.ts file.
This can happen even without explicitly setting declaration: true. For example, composite: true is enough to reproduce because composite TypeScript projects emit declarations by default.
Minimal failing code:
import { formOptions } from '@tanstack/react-form'
export const reproFormOptions = formOptions({
defaultValues: {
country: '',
province: '',
},
listeners: {
onChange: ({ formApi }) => {
formApi.setFieldValue('province', '')
},
},
})
The error is:
src/form-options.ts(12,14): error TS4023: Exported variable 'reproFormOptions' has or is using name 'FormListenersPropsField' from external module ".../node_modules/.pnpm/@tanstack+form-core@1.33.0/node_modules/@tanstack/form-core/dist/esm/FormApi" but cannot be named.
Your minimal, reproducible example
https://codesandbox.io/p/github/jzxhuang/tanstack-form-form-options-type-bug/main?import=true
Steps to reproduce
See codesandbox, snippet above, or https://github.com/jzxhuang/tanstack-form-form-options-type-bug
Expected behavior
TypeScript should be able to emit declarations for an exported formOptions(...) value that uses form listeners.
In particular, the inferred public type of formOptions(...) should not require consumers' declaration emit to name an internal, non-exported TanStack Form type.
How often does this bug happen?
None
Screenshots or Videos
No response
Platform
Reproduces with TypeScript 6.0.3.
Also verified with TypeScript 5.8.3 using:
pnpm --package typescript@5.8.3 dlx tsc -p tsconfig.app.json --pretty false --noEmitOnError
TanStack Form adapter
None
TanStack Form version
1.33.0
TypeScript version
6.0.3
Additional context
No response
Describe the bug
When exporting an inferred
formOptions(...)value that includeslisteners, TypeScript fails during declaration emit withTS4023.The inferred exported type references TanStack Form's internal
FormListenersPropsFieldtype from@tanstack/form-core/dist/esm/FormApi. Since that type is not publicly exported/nameable, TypeScript cannot serialize the exportedformOptions(...)value into a.d.tsfile.This can happen even without explicitly setting
declaration: true. For example,composite: trueis enough to reproduce because composite TypeScript projects emit declarations by default.Minimal failing code:
The error is:
Your minimal, reproducible example
https://codesandbox.io/p/github/jzxhuang/tanstack-form-form-options-type-bug/main?import=true
Steps to reproduce
See codesandbox, snippet above, or https://github.com/jzxhuang/tanstack-form-form-options-type-bug
Expected behavior
TypeScript should be able to emit declarations for an exported
formOptions(...)value that uses formlisteners.In particular, the inferred public type of
formOptions(...)should not require consumers' declaration emit to name an internal, non-exported TanStack Form type.How often does this bug happen?
None
Screenshots or Videos
No response
Platform
TanStack Form adapter
None
TanStack Form version
1.33.0
TypeScript version
6.0.3
Additional context
No response