-
-
Notifications
You must be signed in to change notification settings - Fork 343
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Strictly type check field validators (#409)
* fix: strictly type validators on FieldApi * chore: upgrade vitest to latest * chore: rename test files to remove tsx prefix * test(form-core): add initial type tests
- Loading branch information
1 parent
0b5c94d
commit caba021
Showing
7 changed files
with
317 additions
and
134 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import { assertType } from 'vitest' | ||
import { FormApi } from '../FormApi' | ||
import { FieldApi } from '../FieldApi' | ||
|
||
it('should type a subfield properly', () => { | ||
const form = new FormApi({ | ||
defaultValues: { | ||
names: { | ||
first: 'one', | ||
second: 'two', | ||
}, | ||
} as const, | ||
}) | ||
|
||
const field = new FieldApi({ | ||
form, | ||
name: 'names', | ||
}) | ||
|
||
const subfield = field.getSubField('first') | ||
|
||
assertType<'one'>(subfield.getValue()) | ||
}) | ||
|
||
it('should type onChange properly', () => { | ||
const form = new FormApi({ | ||
defaultValues: { | ||
name: 'test', | ||
}, | ||
} as const) | ||
|
||
const field = new FieldApi({ | ||
form, | ||
name: 'name', | ||
onChange: (value) => { | ||
assertType<'test'>(value) | ||
|
||
return undefined | ||
}, | ||
}) | ||
}) |
File renamed without changes.
Oops, something went wrong.