From 84b265e5b91ee54c23314fa7c1dc50c1a844bd3b Mon Sep 17 00:00:00 2001 From: JounQin Date: Tue, 31 Jul 2018 03:36:31 +0800 Subject: [PATCH] feat: add declarations for hoist-non-react-statics (#27673) --- .../hoist-non-react-statics-tests.ts | 31 +++++++++++++++++++ types/hoist-non-react-statics/index.d.ts | 28 +++++++++++++++++ types/hoist-non-react-statics/tsconfig.json | 23 ++++++++++++++ types/hoist-non-react-statics/tslint.json | 1 + 4 files changed, 83 insertions(+) create mode 100644 types/hoist-non-react-statics/hoist-non-react-statics-tests.ts create mode 100644 types/hoist-non-react-statics/index.d.ts create mode 100644 types/hoist-non-react-statics/tsconfig.json create mode 100644 types/hoist-non-react-statics/tslint.json diff --git a/types/hoist-non-react-statics/hoist-non-react-statics-tests.ts b/types/hoist-non-react-statics/hoist-non-react-statics-tests.ts new file mode 100644 index 0000000000..7065c47410 --- /dev/null +++ b/types/hoist-non-react-statics/hoist-non-react-statics-tests.ts @@ -0,0 +1,31 @@ +import * as React from 'react'; + +import hoistNonReactStatics = require('hoist-non-react-statics'); + +class A extends React.Component { + static a = 'a'; + + getA() { + return A.a; + } +} + +class B extends React.Component { + static b = 'b'; + + getB() { + return B.b; + } +} + +const C = hoistNonReactStatics(A, B); + +C.a !== C.b; + +C.prototype.getA(); // should work +// C.prototype.getB(); // should emit an error + +const D = hoistNonReactStatics(A, B, { b: true }); + +D.a; +// D.b; // should emit an error diff --git a/types/hoist-non-react-statics/index.d.ts b/types/hoist-non-react-statics/index.d.ts new file mode 100644 index 0000000000..f55fb92b6d --- /dev/null +++ b/types/hoist-non-react-statics/index.d.ts @@ -0,0 +1,28 @@ +// Type definitions for hoist-non-react-statics 3.0 +// Project: https://github.com/mridgway/hoist-non-react-statics#readme +// Definitions by: JounQin +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +// TypeScript Version: 2.8 + +import * as React from 'react'; + +declare function hoistNonReactStatics< + T extends React.ComponentType, + S extends React.ComponentType, + C extends { + [key: string]: true + } = {} +>( + TargetComponent: T, + SourceComponent: S, + customStatic?: C, +): T & + { + [key in Exclude< + keyof S, + // only extends static properties, exclude instance properties + 'prototype' | keyof C + >]: S[key] + }; + +export = hoistNonReactStatics; diff --git a/types/hoist-non-react-statics/tsconfig.json b/types/hoist-non-react-statics/tsconfig.json new file mode 100644 index 0000000000..61c70382e5 --- /dev/null +++ b/types/hoist-non-react-statics/tsconfig.json @@ -0,0 +1,23 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": true, + "strictFunctionTypes": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "hoist-non-react-statics-tests.ts" + ] +} diff --git a/types/hoist-non-react-statics/tslint.json b/types/hoist-non-react-statics/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/hoist-non-react-statics/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" }