From f25a05789881db96e80abd6ec133100bb2cf6d7a Mon Sep 17 00:00:00 2001 From: Christoph Spielmann Date: Thu, 20 Jul 2017 23:36:18 +0200 Subject: [PATCH 01/11] Add typings for Reactable 0.14. Not complete but the stuff provided by the typings have been tested/used quite extensively by myself during the development of ReactPlayer! --- types/reactable/index.d.ts | 60 +++++++++++++++++++++++++++++++++++ types/reactable/tsconfig.json | 23 ++++++++++++++ types/reactable/tslint.json | 1 + 3 files changed, 84 insertions(+) create mode 100644 types/reactable/index.d.ts create mode 100644 types/reactable/tsconfig.json create mode 100644 types/reactable/tslint.json diff --git a/types/reactable/index.d.ts b/types/reactable/index.d.ts new file mode 100644 index 0000000000..4509d421c1 --- /dev/null +++ b/types/reactable/index.d.ts @@ -0,0 +1,60 @@ +// Type definitions for reactable 0.14 +// Project: https://github.com/glittershark/reactable +// Definitions by: Christoph Spielmann +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +import * as React from 'react'; + +export interface KeyLabelObject { + key: string; + label: string; +} + +export type ColumnsType = string | KeyLabelObject; + +export type FilterMethodType = (text: string) => void; + +export interface TableComponentProperties { + data?: T[]; + className?: string; + columns?: ColumnsType[]; + id?: string; + sortable?: string[]; + filterable?: string[]; + filterBy?: string; + onFilter?: FilterMethodType; +} + +export interface ThProperties { + column: string; + className?: string; +} + +export interface TrProperties { + data?: T; + className?: string; +} + +export interface TdProperties { + column: string; + value?: any; + data?: any; +} + +export class Table extends React.Component, {}> { +} + +export class Thead extends React.Component<{}, {}> { +} + +export class Th extends React.Component { +} + +export class Tr extends React.Component, {}> { +} + +export class Td extends React.Component { +} + +export class Tfoot extends React.Component<{}, {}> { +} diff --git a/types/reactable/tsconfig.json b/types/reactable/tsconfig.json new file mode 100644 index 0000000000..619dd0b8bf --- /dev/null +++ b/types/reactable/tsconfig.json @@ -0,0 +1,23 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6", + "dom" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true, + "jsx": "react" + }, + "files": [ + "index.d.ts" + ] +} diff --git a/types/reactable/tslint.json b/types/reactable/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/reactable/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" } From 7c3257b794726e53e5f0da2b32dc89d29ee168a2 Mon Sep 17 00:00:00 2001 From: Christoph Spielmann Date: Sat, 22 Jul 2017 16:17:17 +0200 Subject: [PATCH 02/11] Add two tests (very simple one and a quite sophisticated one which contains all the components i created typings for...) --- types/reactable/reactable-tests.tsx | 82 +++++++++++++++++++++++++++++ types/reactable/tsconfig.json | 3 +- 2 files changed, 84 insertions(+), 1 deletion(-) create mode 100644 types/reactable/reactable-tests.tsx diff --git a/types/reactable/reactable-tests.tsx b/types/reactable/reactable-tests.tsx new file mode 100644 index 0000000000..91d80c27ef --- /dev/null +++ b/types/reactable/reactable-tests.tsx @@ -0,0 +1,82 @@ +import * as React from "react"; +import * as ReactDOM from "react-dom"; +import * as Reactable from "reactable"; + +interface Person { + name: string; + age: number; +} + +type PersonTable = new () => Reactable.Table; +const PersonTable = Reactable.Table as PersonTable; + +type PersonTableHeader = new () => Reactable.Thead; +const PersonTableHeader = Reactable.Thead as PersonTableHeader; + +type PersonTableTh = new () => Reactable.Th; +const PersonTableTh = Reactable.Th as PersonTableTh; + +type PersonRow = new () => Reactable.Tr; +const PersonRow = Reactable.Tr as PersonRow; + +type PersonTableTd = new () => Reactable.Td; +const PersonTableTd = Reactable.Td as PersonTableTd; + +type PersonTableTfoot = new () => Reactable.Tfoot; +const PersonTableTfoot = Reactable.Tfoot as PersonTableTfoot; + +let data = [ + { + name: "Christoph Spielmann", + age: 36 + } +]; + +export class TestComponent extends React.Component<{}, {}> { + render(): JSX.Element { + return ; + } +} + +export class FullblownReactableTestComponent extends React.Component<{}, {}> { + render(): JSX.Element { + let displayedColumns = ["name"]; + // custom table Th-elements + let columns: JSX.Element[] = []; + for (let colName of displayedColumns) { + columns.push( + + {colName} + + ); + } + let rows: JSX.Element[] = []; + for (let d of data) { + let tds: JSX.Element[] = []; + displayedColumns.forEach(col => tds.push( + +

d[col]

+
+ )); + rows.push( + + {tds} + + ); + } + return ( + + + {columns} + + {rows} + + + footer cell1 + footer cell2 + + + + ); + } +} diff --git a/types/reactable/tsconfig.json b/types/reactable/tsconfig.json index 619dd0b8bf..c3300f0e32 100644 --- a/types/reactable/tsconfig.json +++ b/types/reactable/tsconfig.json @@ -18,6 +18,7 @@ "jsx": "react" }, "files": [ - "index.d.ts" + "index.d.ts", + "reactable-tests.tsx" ] } From 26c9c3ddf584cbdd38b5829a6ca3666864966efe Mon Sep 17 00:00:00 2001 From: Christoph Spielmann Date: Sun, 27 Aug 2017 17:30:24 +0200 Subject: [PATCH 03/11] Add typings for react-json 0.2! --- types/react-json/index.d.ts | 16 ++++++++++++++++ types/react-json/react-json-tests.tsx | 26 ++++++++++++++++++++++++++ types/react-json/tsconfig.json | 24 ++++++++++++++++++++++++ types/react-json/tslint.json | 1 + 4 files changed, 67 insertions(+) create mode 100644 types/react-json/index.d.ts create mode 100644 types/react-json/react-json-tests.tsx create mode 100644 types/react-json/tsconfig.json create mode 100644 types/react-json/tslint.json diff --git a/types/react-json/index.d.ts b/types/react-json/index.d.ts new file mode 100644 index 0000000000..c52cabcd6b --- /dev/null +++ b/types/react-json/index.d.ts @@ -0,0 +1,16 @@ +// Type definitions for react-json 0.2 +// Project: https://github.com/arqex/react-json +// Definitions by: Christoph Spielmann +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +import * as React from 'react'; + +export type OnChangeHandler = (value: any) => void; + +export interface JsonProperties { + value: any; + onChange?: OnChangeHandler; +} + +export class Json extends React.Component { +} diff --git a/types/react-json/react-json-tests.tsx b/types/react-json/react-json-tests.tsx new file mode 100644 index 0000000000..05e12fa9f9 --- /dev/null +++ b/types/react-json/react-json-tests.tsx @@ -0,0 +1,26 @@ +import * as React from 'react'; +import * as ReactDOM from 'react-dom'; +// import * as Json from 'react-json'; +import { Json } from "react-json"; + +let TestObject = { + s: "Hello, world", + b: true, + n: 666, + o: { + s: "Hello, world", + b: true, + n: 666, + o: { + s: "Hello, world", + b: true, + n: 666, + } + } +}; + +export class TestComponent extends React.Component<{}, {}> { + render(): JSX.Element { + return console.log(val)}/>; + } +} diff --git a/types/react-json/tsconfig.json b/types/react-json/tsconfig.json new file mode 100644 index 0000000000..ff5be5812c --- /dev/null +++ b/types/react-json/tsconfig.json @@ -0,0 +1,24 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6", + "dom" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true, + "jsx": "react" + }, + "files": [ + "index.d.ts", + "react-json-tests.tsx" + ] +} diff --git a/types/react-json/tslint.json b/types/react-json/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/react-json/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" } From d9fb8ed269d2964caf98b4ed2943bc49bf1c51f6 Mon Sep 17 00:00:00 2001 From: Christoph Spielmann Date: Sun, 27 Aug 2017 18:31:22 +0200 Subject: [PATCH 04/11] Fix test... --- types/react-json/react-json-tests.tsx | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/types/react-json/react-json-tests.tsx b/types/react-json/react-json-tests.tsx index 05e12fa9f9..9744ad8855 100644 --- a/types/react-json/react-json-tests.tsx +++ b/types/react-json/react-json-tests.tsx @@ -1,7 +1,8 @@ +/// + import * as React from 'react'; -import * as ReactDOM from 'react-dom'; -// import * as Json from 'react-json'; -import { Json } from "react-json"; +import json = require('react-json'); +let Json = json.Json; let TestObject = { s: "Hello, world", @@ -19,8 +20,4 @@ let TestObject = { } }; -export class TestComponent extends React.Component<{}, {}> { - render(): JSX.Element { - return console.log(val)}/>; - } -} + console.log(val)}/>; From 4412a2503737a9579571e58927e7aa3b0f8ea743 Mon Sep 17 00:00:00 2001 From: Christoph Spielmann Date: Sun, 27 Aug 2017 18:39:10 +0200 Subject: [PATCH 05/11] Sadly i have to use var-require to get this stuff to work... --- types/react-json/react-json-tests.tsx | 3 +-- types/react-json/tslint.json | 8 +++++++- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/types/react-json/react-json-tests.tsx b/types/react-json/react-json-tests.tsx index 9744ad8855..f78c79ce52 100644 --- a/types/react-json/react-json-tests.tsx +++ b/types/react-json/react-json-tests.tsx @@ -1,8 +1,7 @@ /// import * as React from 'react'; -import json = require('react-json'); -let Json = json.Json; +let Json = require('react-json'); let TestObject = { s: "Hello, world", diff --git a/types/react-json/tslint.json b/types/react-json/tslint.json index 3db14f85ea..f46aa2f5f0 100644 --- a/types/react-json/tslint.json +++ b/types/react-json/tslint.json @@ -1 +1,7 @@ -{ "extends": "dtslint/dt.json" } +{ + "extends": "dtslint/dt.json", + "rules": { + "no-var-requires": false + } + +} From 65ebbaec42c8530f98100f3e27c09c6009a72943 Mon Sep 17 00:00:00 2001 From: Christoph Spielmann Date: Sun, 27 Aug 2017 19:02:47 +0200 Subject: [PATCH 06/11] use const instead of let --- types/react-json/react-json-tests.tsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/types/react-json/react-json-tests.tsx b/types/react-json/react-json-tests.tsx index f78c79ce52..d4324d566b 100644 --- a/types/react-json/react-json-tests.tsx +++ b/types/react-json/react-json-tests.tsx @@ -1,9 +1,9 @@ /// import * as React from 'react'; -let Json = require('react-json'); +const Json = require('react-json'); -let TestObject = { +const TestObject = { s: "Hello, world", b: true, n: 666, From fd71eaa751f1aea2a3a7ac9accdf4c2a0ffba411 Mon Sep 17 00:00:00 2001 From: Christoph Spielmann Date: Sun, 27 Aug 2017 19:10:33 +0200 Subject: [PATCH 07/11] Remove unnecessary type-parameter... --- types/react-json/index.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/types/react-json/index.d.ts b/types/react-json/index.d.ts index c52cabcd6b..6887a948b8 100644 --- a/types/react-json/index.d.ts +++ b/types/react-json/index.d.ts @@ -12,5 +12,5 @@ export interface JsonProperties { onChange?: OnChangeHandler; } -export class Json extends React.Component { +export class Json extends React.Component { } From b8adfa8040dce13d9d848cf25a69dee8f369beb1 Mon Sep 17 00:00:00 2001 From: Christoph Spielmann Date: Sun, 27 Aug 2017 19:18:32 +0200 Subject: [PATCH 08/11] Make sure that at least version 2.3 of TypeScript is used... --- types/react-json/index.d.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/types/react-json/index.d.ts b/types/react-json/index.d.ts index 6887a948b8..0af43ad946 100644 --- a/types/react-json/index.d.ts +++ b/types/react-json/index.d.ts @@ -2,6 +2,7 @@ // Project: https://github.com/arqex/react-json // Definitions by: Christoph Spielmann // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +// TypeScript Version: 2.3 import * as React from 'react'; From ac0c6f0669846a9a52a6055ff00e2a811c6548b4 Mon Sep 17 00:00:00 2001 From: Christoph Spielmann Date: Sun, 27 Aug 2017 23:23:07 +0200 Subject: [PATCH 09/11] Rewrite typings to actually make sense (and adjust test accordingly) --- types/react-json/index.d.ts | 9 ++++++--- types/react-json/react-json-tests.tsx | 4 +--- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/types/react-json/index.d.ts b/types/react-json/index.d.ts index 0af43ad946..759b8bfe86 100644 --- a/types/react-json/index.d.ts +++ b/types/react-json/index.d.ts @@ -6,12 +6,15 @@ import * as React from 'react'; -export type OnChangeHandler = (value: any) => void; +type OnChangeHandler = (value: any) => void; -export interface JsonProperties { +interface JsonProperties { value: any; onChange?: OnChangeHandler; } -export class Json extends React.Component { +declare class Json extends React.Component { } + +export default Json; + diff --git a/types/react-json/react-json-tests.tsx b/types/react-json/react-json-tests.tsx index d4324d566b..6bad322c9c 100644 --- a/types/react-json/react-json-tests.tsx +++ b/types/react-json/react-json-tests.tsx @@ -1,7 +1,5 @@ -/// - import * as React from 'react'; -const Json = require('react-json'); +import Json from 'react-json'; const TestObject = { s: "Hello, world", From 2cbfb52fbdec1255c5689084d2e91126fea9bfb2 Mon Sep 17 00:00:00 2001 From: Christoph Spielmann Date: Sun, 27 Aug 2017 23:30:06 +0200 Subject: [PATCH 10/11] Changes for linting... --- types/react-json/index.d.ts | 1 - types/react-json/tslint.json | 6 +----- 2 files changed, 1 insertion(+), 6 deletions(-) diff --git a/types/react-json/index.d.ts b/types/react-json/index.d.ts index 759b8bfe86..90b5b202dc 100644 --- a/types/react-json/index.d.ts +++ b/types/react-json/index.d.ts @@ -17,4 +17,3 @@ declare class Json extends React.Component { } export default Json; - diff --git a/types/react-json/tslint.json b/types/react-json/tslint.json index f46aa2f5f0..f93cf8562a 100644 --- a/types/react-json/tslint.json +++ b/types/react-json/tslint.json @@ -1,7 +1,3 @@ { - "extends": "dtslint/dt.json", - "rules": { - "no-var-requires": false - } - + "extends": "dtslint/dt.json" } From 51ae998e9da3ab430395ee9cab741051a1539bbf Mon Sep 17 00:00:00 2001 From: Christoph Spielmann Date: Mon, 28 Aug 2017 23:07:31 +0200 Subject: [PATCH 11/11] Replace export default with export = --- types/react-json/index.d.ts | 2 +- types/react-json/tsconfig.json | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/types/react-json/index.d.ts b/types/react-json/index.d.ts index 90b5b202dc..58bfd488f8 100644 --- a/types/react-json/index.d.ts +++ b/types/react-json/index.d.ts @@ -16,4 +16,4 @@ interface JsonProperties { declare class Json extends React.Component { } -export default Json; +export = Json; diff --git a/types/react-json/tsconfig.json b/types/react-json/tsconfig.json index ff5be5812c..3363d26f86 100644 --- a/types/react-json/tsconfig.json +++ b/types/react-json/tsconfig.json @@ -15,7 +15,8 @@ "types": [], "noEmit": true, "forceConsistentCasingInFileNames": true, - "jsx": "react" + "jsx": "react", + "allowSyntheticDefaultImports": true }, "files": [ "index.d.ts",