From 5ae724d49135cd76d4a2c7d0ab5a8f4f1cb407e0 Mon Sep 17 00:00:00 2001 From: Chris Dopuch Date: Sun, 20 Jan 2019 17:58:44 -0800 Subject: [PATCH 1/8] add generic type to single-spa-react rootComponent --- types/single-spa-react/index.d.ts | 37 +++++++++++++++++-------------- 1 file changed, 20 insertions(+), 17 deletions(-) diff --git a/types/single-spa-react/index.d.ts b/types/single-spa-react/index.d.ts index 82656bfaf5..7ab25ca130 100644 --- a/types/single-spa-react/index.d.ts +++ b/types/single-spa-react/index.d.ts @@ -1,29 +1,32 @@ // Type definitions for single-spa-react 2.8 // Project: https://github.com/CanopyTax/single-spa-react // Definitions by: Garrett Smith +// Chris Dopuch // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped // TypeScript Version: 2.8 -import * as React from 'react'; -import * as ReactDOM from 'react-dom'; +import * as React from "react"; +import * as ReactDOM from "react-dom"; export = SingleSpaReact; -declare function SingleSpaReact(opts: SingleSpaReact.Options): SingleSpaReact.Lifecycles; +declare function SingleSpaReact( + opts: SingleSpaReact.Options +): SingleSpaReact.Lifecycles; declare namespace SingleSpaReact { - interface Options { - React: typeof React; - ReactDOM: typeof ReactDOM; - rootComponent?: React.ComponentClass; - loadRootComponent?: () => Promise; - domElementGetter?: () => Element; - suppressComponentDidCatchWarning?: boolean; - parcelCanUpdate?: boolean; - } + interface Options { + React: typeof React; + ReactDOM: typeof ReactDOM; + rootComponent?: T; + loadRootComponent?: () => Promise; + domElementGetter?: () => Element; + suppressComponentDidCatchWarning?: boolean; + parcelCanUpdate?: boolean; + } - interface Lifecycles { - bootstrap: (opts: Options, props: any) => Promise; - mount: (opts: Options, props: any) => Promise; - unmount: (opts: Options, props: any) => Promise; - } + interface Lifecycles { + bootstrap: (props: any) => Promise; + mount: (props: any) => Promise; + unmount: (props: any) => Promise; + } } From 8f6a4717c4a26203db20cfff5964c6df2795505e Mon Sep 17 00:00:00 2001 From: Chris Dopuch Date: Sun, 20 Jan 2019 18:27:57 -0800 Subject: [PATCH 2/8] add tests, package.json --- types/single-spa-react/package.json | 11 +++++++++++ types/single-spa-react/single-spa-react-tests.ts | 10 ---------- .../single-spa-react/single-spa-react-tests.tsx | 16 ++++++++++++++++ types/single-spa-react/tsconfig.json | 14 +++----------- types/single-spa-react/tslint.json | 2 +- 5 files changed, 31 insertions(+), 22 deletions(-) create mode 100644 types/single-spa-react/package.json delete mode 100644 types/single-spa-react/single-spa-react-tests.ts create mode 100644 types/single-spa-react/single-spa-react-tests.tsx diff --git a/types/single-spa-react/package.json b/types/single-spa-react/package.json new file mode 100644 index 0000000000..d4e3f38146 --- /dev/null +++ b/types/single-spa-react/package.json @@ -0,0 +1,11 @@ +{ + "private": true, + "dependencies": { + "react": "^16.7.0", + "react-dom": "^16.7.0", + "single-spa-react": "^2.9.0" + }, + "scripts": { + "test": "tsc -p tsconfig.json" + } +} diff --git a/types/single-spa-react/single-spa-react-tests.ts b/types/single-spa-react/single-spa-react-tests.ts deleted file mode 100644 index 7efed91489..0000000000 --- a/types/single-spa-react/single-spa-react-tests.ts +++ /dev/null @@ -1,10 +0,0 @@ -import singleSpaReact = require('single-spa-react'); -import { Lifecycles } from 'single-spa-react'; -import * as React from 'react'; -import * as ReactDOM from 'react-dom'; - -// $ExpectType Lifecycles -singleSpaReact({ - React, - ReactDOM, -}); diff --git a/types/single-spa-react/single-spa-react-tests.tsx b/types/single-spa-react/single-spa-react-tests.tsx new file mode 100644 index 0000000000..53c8a81e77 --- /dev/null +++ b/types/single-spa-react/single-spa-react-tests.tsx @@ -0,0 +1,16 @@ +import singleSpaReact = require("single-spa-react"); +import * as React from "react"; +import * as ReactDOM from "react-dom"; + +type customProps = { name: string }; + +const rootComponent: React.SFC = (props: customProps) => { + return
hello{props.name} !
; +}; + +// $ExpectType Lifecycles +singleSpaReact({ + React, + ReactDOM, + rootComponent +}); diff --git a/types/single-spa-react/tsconfig.json b/types/single-spa-react/tsconfig.json index 4204827d4d..4bf3b7e965 100644 --- a/types/single-spa-react/tsconfig.json +++ b/types/single-spa-react/tsconfig.json @@ -1,24 +1,16 @@ { "compilerOptions": { "module": "commonjs", - "lib": [ - "es6", - "dom" - ], + "lib": ["es6", "dom"], + "jsx": "react", "noImplicitAny": true, "noImplicitThis": true, "strictFunctionTypes": true, "strictNullChecks": true, "baseUrl": "../", - "typeRoots": [ - "../" - ], "types": [], "noEmit": true, "forceConsistentCasingInFileNames": true }, - "files": [ - "index.d.ts", - "single-spa-react-tests.ts" - ] + "files": ["index.d.ts", "single-spa-react-tests.tsx"] } diff --git a/types/single-spa-react/tslint.json b/types/single-spa-react/tslint.json index 3db14f85ea..30bd6d7388 100644 --- a/types/single-spa-react/tslint.json +++ b/types/single-spa-react/tslint.json @@ -1 +1 @@ -{ "extends": "dtslint/dt.json" } +{ "extends": ["dtslint/dt.json", "tslint-react"] } From 80dbf7e3a6e649917956182778058b58ea701e02 Mon Sep 17 00:00:00 2001 From: Chris Dopuch Date: Sun, 20 Jan 2019 18:35:46 -0800 Subject: [PATCH 3/8] dtslint for test --- types/single-spa-react/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/types/single-spa-react/package.json b/types/single-spa-react/package.json index d4e3f38146..1221497660 100644 --- a/types/single-spa-react/package.json +++ b/types/single-spa-react/package.json @@ -6,6 +6,6 @@ "single-spa-react": "^2.9.0" }, "scripts": { - "test": "tsc -p tsconfig.json" + "test": "dtslint -p tsconfig.json" } } From 75c5f990afb9ea84d7c1ce0dad2fdff186b7dc0c Mon Sep 17 00:00:00 2001 From: Chris Dopuch Date: Sun, 20 Jan 2019 18:41:46 -0800 Subject: [PATCH 4/8] remove extra package.json stuff --- types/single-spa-react/package.json | 5 ----- 1 file changed, 5 deletions(-) diff --git a/types/single-spa-react/package.json b/types/single-spa-react/package.json index 1221497660..3384df63c7 100644 --- a/types/single-spa-react/package.json +++ b/types/single-spa-react/package.json @@ -1,11 +1,6 @@ { "private": true, "dependencies": { - "react": "^16.7.0", - "react-dom": "^16.7.0", "single-spa-react": "^2.9.0" - }, - "scripts": { - "test": "dtslint -p tsconfig.json" } } From e56af159cbced48982725490205ba5691b803f6a Mon Sep 17 00:00:00 2001 From: Chris Dopuch Date: Sun, 20 Jan 2019 18:43:23 -0800 Subject: [PATCH 5/8] remove package.json --- types/single-spa-react/package.json | 6 ------ 1 file changed, 6 deletions(-) delete mode 100644 types/single-spa-react/package.json diff --git a/types/single-spa-react/package.json b/types/single-spa-react/package.json deleted file mode 100644 index 3384df63c7..0000000000 --- a/types/single-spa-react/package.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "private": true, - "dependencies": { - "single-spa-react": "^2.9.0" - } -} From 3dddf04ac63aed84dd836bbe1dd09857201db55d Mon Sep 17 00:00:00 2001 From: Chris Dopuch Date: Sun, 20 Jan 2019 18:46:35 -0800 Subject: [PATCH 6/8] revert linting change --- types/single-spa-react/tslint.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/types/single-spa-react/tslint.json b/types/single-spa-react/tslint.json index 30bd6d7388..3db14f85ea 100644 --- a/types/single-spa-react/tslint.json +++ b/types/single-spa-react/tslint.json @@ -1 +1 @@ -{ "extends": ["dtslint/dt.json", "tslint-react"] } +{ "extends": "dtslint/dt.json" } From 3d6cddd5c3e28730c8eb526c29eb9142f3b85199 Mon Sep 17 00:00:00 2001 From: Chris Dopuch Date: Sun, 20 Jan 2019 18:49:14 -0800 Subject: [PATCH 7/8] fix tsconfig, reimport in test --- types/single-spa-react/single-spa-react-tests.tsx | 5 ++++- types/single-spa-react/tsconfig.json | 1 + 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/types/single-spa-react/single-spa-react-tests.tsx b/types/single-spa-react/single-spa-react-tests.tsx index 53c8a81e77..1b42050146 100644 --- a/types/single-spa-react/single-spa-react-tests.tsx +++ b/types/single-spa-react/single-spa-react-tests.tsx @@ -1,8 +1,11 @@ import singleSpaReact = require("single-spa-react"); +import { Lifecycles } from "single-spa-react"; import * as React from "react"; import * as ReactDOM from "react-dom"; -type customProps = { name: string }; +interface customProps { + name: string; +} const rootComponent: React.SFC = (props: customProps) => { return
hello{props.name} !
; diff --git a/types/single-spa-react/tsconfig.json b/types/single-spa-react/tsconfig.json index 4bf3b7e965..a2b1f12071 100644 --- a/types/single-spa-react/tsconfig.json +++ b/types/single-spa-react/tsconfig.json @@ -8,6 +8,7 @@ "strictFunctionTypes": true, "strictNullChecks": true, "baseUrl": "../", + "typeRoots": ["../"], "types": [], "noEmit": true, "forceConsistentCasingInFileNames": true From 16f000c1707493b3d9a2ace4a5009daa2f8d892f Mon Sep 17 00:00:00 2001 From: Chris Dopuch Date: Sun, 20 Jan 2019 19:02:32 -0800 Subject: [PATCH 8/8] use class, no generic --- types/single-spa-react/index.d.ts | 10 +++++----- types/single-spa-react/single-spa-react-tests.tsx | 8 +++++--- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/types/single-spa-react/index.d.ts b/types/single-spa-react/index.d.ts index 7ab25ca130..9769d41963 100644 --- a/types/single-spa-react/index.d.ts +++ b/types/single-spa-react/index.d.ts @@ -9,16 +9,16 @@ import * as React from "react"; import * as ReactDOM from "react-dom"; export = SingleSpaReact; -declare function SingleSpaReact( - opts: SingleSpaReact.Options +declare function SingleSpaReact( + opts: SingleSpaReact.Options ): SingleSpaReact.Lifecycles; declare namespace SingleSpaReact { - interface Options { + interface Options { React: typeof React; ReactDOM: typeof ReactDOM; - rootComponent?: T; - loadRootComponent?: () => Promise; + rootComponent?: React.ComponentClass; + loadRootComponent?: () => Promise>; domElementGetter?: () => Element; suppressComponentDidCatchWarning?: boolean; parcelCanUpdate?: boolean; diff --git a/types/single-spa-react/single-spa-react-tests.tsx b/types/single-spa-react/single-spa-react-tests.tsx index 1b42050146..b9350fdb04 100644 --- a/types/single-spa-react/single-spa-react-tests.tsx +++ b/types/single-spa-react/single-spa-react-tests.tsx @@ -7,9 +7,11 @@ interface customProps { name: string; } -const rootComponent: React.SFC = (props: customProps) => { - return
hello{props.name} !
; -}; +class rootComponent extends React.Component { + render() { + return
hello{this.props.name} !
; + } +} // $ExpectType Lifecycles singleSpaReact({