Skip to content

Commit

Permalink
feat: add declarations for hoist-non-react-statics (DefinitelyTyped#2…
Browse files Browse the repository at this point in the history
  • Loading branch information
JounQin authored and sheetalkamat committed Jul 30, 2018
1 parent 31c4ba6 commit 84b265e
Show file tree
Hide file tree
Showing 4 changed files with 83 additions and 0 deletions.
31 changes: 31 additions & 0 deletions types/hoist-non-react-statics/hoist-non-react-statics-tests.ts
Original file line number Diff line number Diff line change
@@ -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
28 changes: 28 additions & 0 deletions types/hoist-non-react-statics/index.d.ts
Original file line number Diff line number Diff line change
@@ -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 <https://github.com/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;
23 changes: 23 additions & 0 deletions types/hoist-non-react-statics/tsconfig.json
Original file line number Diff line number Diff line change
@@ -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"
]
}
1 change: 1 addition & 0 deletions types/hoist-non-react-statics/tslint.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{ "extends": "dtslint/dt.json" }

0 comments on commit 84b265e

Please sign in to comment.