forked from DefinitelyTyped/DefinitelyTyped
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add declarations for hoist-non-react-statics (DefinitelyTyped#2…
- Loading branch information
1 parent
31c4ba6
commit 84b265e
Showing
4 changed files
with
83 additions
and
0 deletions.
There are no files selected for viewing
31 changes: 31 additions & 0 deletions
31
types/hoist-non-react-statics/hoist-non-react-statics-tests.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{ "extends": "dtslint/dt.json" } |