Skip to content

Add definition #5

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 20, 2018
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
11 changes: 9 additions & 2 deletions package-scripts.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ const npsUtils = require('nps-utils')
const series = npsUtils.series
const concurrent = npsUtils.concurrent
const rimraf = npsUtils.rimraf

module.exports = {
scripts: {
size: {
Expand All @@ -17,7 +18,8 @@ module.exports = {
'build.es',
'build.cjs',
'build.umd.main',
'build.umd.min'
'build.umd.min',
'copyTypes'
)
),
es: {
Expand All @@ -40,6 +42,7 @@ module.exports = {
},
andTest: series.nps('build', 'size')
},
copyTypes: series(npsUtils.copy('src/*.d.ts dist')),
docs: {
description: 'Generates table of contents in README',
script: 'doctoc README.md'
Expand All @@ -48,10 +51,14 @@ module.exports = {
description: 'lint the entire project',
script: 'eslint .'
},
typescript: {
description: 'typescript check the entire project',
script: 'tsc'
},
validate: {
description:
'This runs several scripts to make sure things look good before committing or on clean install',
default: concurrent.nps('lint', 'build.andTest')
default: concurrent.nps('lint', 'build.andTest', 'typescript')
}
},
options: {
Expand Down
50 changes: 50 additions & 0 deletions src/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import {
FormApi,
Config,
FormState,
FormSubscription,
FieldSubscription,
FieldState
} from 'final-form'

export interface FormRenderProps extends FormState {
form: FormApi
handleSubmit: (
event?: React.SyntheticEvent<HTMLFormElement>
) => Promise<object | undefined> | undefined
}

interface FormConfig extends Config {
subscription?: FormSubscription
}

type NonFunctionPropertyNames<T> = {
[K in keyof T]: T[K] extends Function ? never : K
}[keyof T]
type NonFunctionProperties<T> = Pick<T, NonFunctionPropertyNames<T>>

export interface FieldRenderProps {
input: {
name: string
onBlur: <T>(event?: React.FocusEvent<T>) => void
onChange: <T>(event: React.ChangeEvent<T> | any) => void
onFocus: <T>(event?: React.FocusEvent<T>) => void
value: any
checked?: boolean
}
meta: NonFunctionProperties<FieldState>
}

interface FormConfig extends Config {
subscription?: FormSubscription
}

declare module 'react-final-form-hooks' {
export function useForm(config: FormConfig): FormRenderProps

export function useField(
name: string,
form: FormApi,
subscription?: FieldSubscription
): FieldRenderProps
}
9 changes: 9 additions & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"compilerOptions": {
"lib": ["es2015", "dom"],
"baseUrl": ".",
"noEmit": true,
"strict": true
},
"include": ["./src/**/*"]
}