Skip to content
This repository was archived by the owner on Oct 16, 2025. It is now read-only.

Commit acb3cb2

Browse files
huan086orta
authored andcommitted
[final-form-focus] Add Typescript definitions. (DefinitelyTyped#38200)
1 parent 2ef13b1 commit acb3cb2

5 files changed

Lines changed: 67 additions & 0 deletions

File tree

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { Decorator, getIn } from 'final-form';
2+
import createDecorator, { FindInput, FocusableInput, getFormInputs, GetInputs } from 'final-form-focus';
3+
4+
createDecorator(); // $ExpectType Decorator<object>
5+
6+
const inputs = getFormInputs('formName'); // $ExpectType GetInputs
7+
createDecorator(inputs); // $ExpectType Decorator<object>
8+
9+
const findInput: FindInput = (inputs: FocusableInput[], errors: object) =>
10+
inputs.find(input => input.name && getIn(errors, input.name));
11+
12+
createDecorator(inputs, findInput); // $ExpectType Decorator<object>

types/final-form-focus/index.d.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// Type definitions for final-form-focus 1.1
2+
// Project: https://github.com/final-form/final-form-focus
3+
// Definitions by: Jeow Li Huan <https://github.com/huan086>
4+
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
5+
// TypeScript Version: 2.8
6+
7+
import { Decorator } from 'final-form';
8+
9+
export interface FocusableInput {
10+
name: string;
11+
focus: () => void;
12+
}
13+
14+
export type GetInputs = () => FocusableInput[];
15+
16+
export type FindInput = (inputs: FocusableInput[], errors: object) => FocusableInput | undefined;
17+
18+
export default function createDecorator(
19+
getInputs?: GetInputs,
20+
findInput?: FindInput,
21+
): Decorator;
22+
23+
export function getFormInputs(formName: string): GetInputs;
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"private": true,
3+
"dependencies": {
4+
"final-form": "4.x.x"
5+
}
6+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
{
2+
"compilerOptions": {
3+
"module": "commonjs",
4+
"lib": [
5+
"es6",
6+
"dom"
7+
],
8+
"noImplicitAny": true,
9+
"noImplicitThis": true,
10+
"strictNullChecks": true,
11+
"strictFunctionTypes": true,
12+
"baseUrl": "../",
13+
"jsx": "react",
14+
"typeRoots": [
15+
"../"
16+
],
17+
"types": [],
18+
"noEmit": true,
19+
"forceConsistentCasingInFileNames": true
20+
},
21+
"files": [
22+
"index.d.ts",
23+
"final-form-focus-tests.tsx"
24+
]
25+
}

types/final-form-focus/tslint.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{ "extends": "dtslint/dt.json" }

0 commit comments

Comments
 (0)