From f5f34f814e55ebef2e3940144ad7804d71caecf5 Mon Sep 17 00:00:00 2001 From: lukostry Date: Thu, 14 Feb 2019 11:58:29 +0100 Subject: [PATCH 1/2] Add definitions for ink-text-input --- types/ink-text-input/index.d.ts | 17 +++++++ types/ink-text-input/ink-text-input-tests.tsx | 44 +++++++++++++++++++ types/ink-text-input/tsconfig.json | 24 ++++++++++ types/ink-text-input/tslint.json | 1 + 4 files changed, 86 insertions(+) create mode 100644 types/ink-text-input/index.d.ts create mode 100644 types/ink-text-input/ink-text-input-tests.tsx create mode 100644 types/ink-text-input/tsconfig.json create mode 100644 types/ink-text-input/tslint.json diff --git a/types/ink-text-input/index.d.ts b/types/ink-text-input/index.d.ts new file mode 100644 index 0000000000..1d7192e1dc --- /dev/null +++ b/types/ink-text-input/index.d.ts @@ -0,0 +1,17 @@ +// Type definitions for ink-text-input 2.0 +// Project: https://github.com/vadimdemedes/ink-text-input#readme +// Definitions by: Ɓukasz Ostrowski +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +// TypeScript Version: 2.8 + +import { Component } from 'ink'; + +export interface TextInputProps { + focus?: boolean; + onChange?: (value: string) => void; + onSubmit?: (value: string) => void; + placeholder?: string; + value?: string; +} + +export default class TextInput extends Component { } diff --git a/types/ink-text-input/ink-text-input-tests.tsx b/types/ink-text-input/ink-text-input-tests.tsx new file mode 100644 index 0000000000..ada8ab3a83 --- /dev/null +++ b/types/ink-text-input/ink-text-input-tests.tsx @@ -0,0 +1,44 @@ +/** @jsx h */ +import { h, Component } from 'ink'; +import TextInput from 'ink-text-input'; + +interface QueryState { + query: string; +} + +class SearchQuery extends Component { + constructor() { + super(); + + this.state = { + query: '' + }; + + this.handleChange = this.handleChange.bind(this); + this.handleSubmit = this.handleSubmit.bind(this); + } + + render(props: {}, state: QueryState) { + return ( +
+ Enter your query: + + +
+ ); + } + + private handleChange(value: string) { + this.setState({ + query: value, + }); + } + + private handleSubmit(value: string) { + console.log(value); + } +} diff --git a/types/ink-text-input/tsconfig.json b/types/ink-text-input/tsconfig.json new file mode 100644 index 0000000000..f58efc92ff --- /dev/null +++ b/types/ink-text-input/tsconfig.json @@ -0,0 +1,24 @@ +{ + "compilerOptions": { + "jsx": "react", + "module": "commonjs", + "lib": [ + "es6" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictFunctionTypes": true, + "strictNullChecks": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "ink-text-input-tests.tsx" + ] +} diff --git a/types/ink-text-input/tslint.json b/types/ink-text-input/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/ink-text-input/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" } From 040acad4340896be2dbfa5faac0a79cf170cfb4f Mon Sep 17 00:00:00 2001 From: lukostry Date: Fri, 15 Feb 2019 13:00:37 +0100 Subject: [PATCH 2/2] Do not use default export --- types/ink-text-input/index.d.ts | 6 ++++-- types/ink-text-input/ink-text-input-tests.tsx | 3 +++ types/ink-text-input/tsconfig.json | 1 + 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/types/ink-text-input/index.d.ts b/types/ink-text-input/index.d.ts index 1d7192e1dc..9aaadd330e 100644 --- a/types/ink-text-input/index.d.ts +++ b/types/ink-text-input/index.d.ts @@ -6,7 +6,7 @@ import { Component } from 'ink'; -export interface TextInputProps { +interface TextInputProps { focus?: boolean; onChange?: (value: string) => void; onSubmit?: (value: string) => void; @@ -14,4 +14,6 @@ export interface TextInputProps { value?: string; } -export default class TextInput extends Component { } +declare class TextInput extends Component { } + +export = TextInput; diff --git a/types/ink-text-input/ink-text-input-tests.tsx b/types/ink-text-input/ink-text-input-tests.tsx index ada8ab3a83..82b63854a2 100644 --- a/types/ink-text-input/ink-text-input-tests.tsx +++ b/types/ink-text-input/ink-text-input-tests.tsx @@ -1,6 +1,9 @@ /** @jsx h */ import { h, Component } from 'ink'; import TextInput from 'ink-text-input'; +// NOTE: `import TextInput = require('ink-text-input');` will work as well +// For importing using ES6 default import as above, +// `allowSyntheticDefaultImports` flag in compiler options needs to be set to `true` interface QueryState { query: string; diff --git a/types/ink-text-input/tsconfig.json b/types/ink-text-input/tsconfig.json index f58efc92ff..2582b4325e 100644 --- a/types/ink-text-input/tsconfig.json +++ b/types/ink-text-input/tsconfig.json @@ -1,5 +1,6 @@ { "compilerOptions": { + "allowSyntheticDefaultImports": true, "jsx": "react", "module": "commonjs", "lib": [