feat: add declarations for hoist-non-react-statics (#27673)

This commit is contained in:
JounQin 2018-07-31 03:36:31 +08:00 committed by Sheetal Nandi
parent 31c4ba6176
commit 84b265e5b9
4 changed files with 83 additions and 0 deletions

View File

@ -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

View File

@ -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;

View File

@ -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"
]
}

View File

@ -0,0 +1 @@
{ "extends": "dtslint/dt.json" }