mirror of
https://github.com/FlipsideCrypto/DefinitelyTyped.git
synced 2026-02-06 10:56:53 +00:00
feat: add declarations for hoist-non-react-statics (#27673)
This commit is contained in:
parent
31c4ba6176
commit
84b265e5b9
@ -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
types/hoist-non-react-statics/index.d.ts
vendored
Normal file
28
types/hoist-non-react-statics/index.d.ts
vendored
Normal 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;
|
||||
23
types/hoist-non-react-statics/tsconfig.json
Normal file
23
types/hoist-non-react-statics/tsconfig.json
Normal 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"
|
||||
]
|
||||
}
|
||||
1
types/hoist-non-react-statics/tslint.json
Normal file
1
types/hoist-non-react-statics/tslint.json
Normal file
@ -0,0 +1 @@
|
||||
{ "extends": "dtslint/dt.json" }
|
||||
Loading…
Reference in New Issue
Block a user