[final-form-focus] Add Typescript definitions. (#38200)

This commit is contained in:
Jeow Li Huan 2019-09-18 03:04:16 +08:00 committed by Orta
parent 2ef13b1431
commit acb3cb292b
5 changed files with 67 additions and 0 deletions

View File

@ -0,0 +1,12 @@
import { Decorator, getIn } from 'final-form';
import createDecorator, { FindInput, FocusableInput, getFormInputs, GetInputs } from 'final-form-focus';
createDecorator(); // $ExpectType Decorator<object>
const inputs = getFormInputs('formName'); // $ExpectType GetInputs
createDecorator(inputs); // $ExpectType Decorator<object>
const findInput: FindInput = (inputs: FocusableInput[], errors: object) =>
inputs.find(input => input.name && getIn(errors, input.name));
createDecorator(inputs, findInput); // $ExpectType Decorator<object>

23
types/final-form-focus/index.d.ts vendored Normal file
View File

@ -0,0 +1,23 @@
// Type definitions for final-form-focus 1.1
// Project: https://github.com/final-form/final-form-focus
// Definitions by: Jeow Li Huan <https://github.com/huan086>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.8
import { Decorator } from 'final-form';
export interface FocusableInput {
name: string;
focus: () => void;
}
export type GetInputs = () => FocusableInput[];
export type FindInput = (inputs: FocusableInput[], errors: object) => FocusableInput | undefined;
export default function createDecorator(
getInputs?: GetInputs,
findInput?: FindInput,
): Decorator;
export function getFormInputs(formName: string): GetInputs;

View File

@ -0,0 +1,6 @@
{
"private": true,
"dependencies": {
"final-form": "4.x.x"
}
}

View File

@ -0,0 +1,25 @@
{
"compilerOptions": {
"module": "commonjs",
"lib": [
"es6",
"dom"
],
"noImplicitAny": true,
"noImplicitThis": true,
"strictNullChecks": true,
"strictFunctionTypes": true,
"baseUrl": "../",
"jsx": "react",
"typeRoots": [
"../"
],
"types": [],
"noEmit": true,
"forceConsistentCasingInFileNames": true
},
"files": [
"index.d.ts",
"final-form-focus-tests.tsx"
]
}

View File

@ -0,0 +1 @@
{ "extends": "dtslint/dt.json" }