Skip to content
This repository was archived by the owner on Feb 14, 2023. It is now read-only.

Commit 0d1d9f0

Browse files
author
Charles Stover
committed
resolves #88
1 parent 16d6c66 commit 0d1d9f0

File tree

6 files changed

+52
-25
lines changed

6 files changed

+52
-25
lines changed

.eslintrc.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ module.exports = {
3030
'warn', 2, {
3131
SwitchCase: 1,
3232
} ],
33+
'@typescript-eslint/no-empty-interface': 'off',
34+
'@typescript-eslint/no-namespace': 'off',
3335
'@typescript-eslint/no-unused-vars': [
3436
'error', {
3537
args: 'all',

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "reactn",
3-
"version": "2.1.1",
3+
"version": "2.1.2",
44
"author": "Charles Stover <[email protected]>",
55
"description": "React, but with built-in global state management.",
66
"homepage": "https://github.com/CharlesStover/reactn#readme",

src/index.ts

Lines changed: 33 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import React = require('react');
21
import { Reducers, State } from '../default';
32
import Callback from '../types/callback';
43
import {
@@ -8,6 +7,7 @@ import {
87
import Dispatcher, { ExtractArguments } from '../types/dispatcher';
98
import Dispatchers from '../types/dispatchers';
109
import NewGlobalState from '../types/new-global-state';
10+
import Omit from '../types/omit';
1111
import ReactNProvider from '../types/provider';
1212
import Reducer, { AdditionalReducers } from '../types/reducer';
1313
import { GlobalTuple, StateTuple } from '../types/use-global';
@@ -27,12 +27,13 @@ import setGlobal from './set-global';
2727
import useDispatch from './use-dispatch';
2828
import useGlobal from './use-global';
2929
import withGlobal from './with-global';
30+
import React = require('react');
3031

3132

3233

3334
type BooleanFunction = () => boolean;
3435

35-
interface ReactN extends TypeOfReact {
36+
interface ReactN extends Omit<typeof React, 'Component' | 'default' | 'PureComponent'> {
3637

3738
<P extends {} = {}, S extends {} = {}, G extends {} = State, R extends {} = Reducers, SS = any>(
3839
DecoratedComponent: React.ComponentClass<P, S>,
@@ -51,8 +52,6 @@ interface ReactN extends TypeOfReact {
5152
reducers: AdditionalReducers<G, R>,
5253
): BooleanFunction;
5354

54-
Component: ReactNComponentClass;
55-
5655
createProvider<G extends {} = State, R extends {} = Reducers>(
5756
initialState?: G,
5857
initialReducers?: R,
@@ -65,8 +64,6 @@ interface ReactN extends TypeOfReact {
6564

6665
getGlobal<G extends {} = State>(): G;
6766

68-
PureComponent: ReactNPureComponentClass;
69-
7067
removeCallback<G extends {} = State>(
7168
callback: Callback<G>,
7269
): boolean;
@@ -102,21 +99,45 @@ interface ReactN extends TypeOfReact {
10299
}
103100

104101
declare namespace ReactNTypes {
102+
103+
interface Component<
104+
P extends {} = {},
105+
S extends {} = {},
106+
G extends {} = State,
107+
R extends {} = Reducers,
108+
SS = any,
109+
> extends ReactNComponent<P, S, G, R, SS> { }
110+
105111
interface ComponentClass<
106112
P extends {} = {},
107113
S extends {} = {},
108114
G extends {} = State,
109115
R extends {} = Reducers,
110-
SS = any
111-
> extends React.ComponentClass<P, S> {
112-
new (props: P, context?: any): ReactNComponent<P, S, G, R, SS>;
113-
}
116+
SS = any,
117+
> extends ReactNComponentClass<P, S, G, R, SS> { }
114118

119+
interface PureComponent<
120+
P extends {} = {},
121+
S extends {} = {},
122+
G extends {} = State,
123+
R extends {} = Reducers,
124+
SS = any,
125+
> extends ReactNPureComponent<P, S, G, R, SS> { }
126+
127+
interface PureComponentClass<
128+
P extends {} = {},
129+
S extends {} = {},
130+
G extends {} = State,
131+
R extends {} = Reducers,
132+
SS = any,
133+
> extends ReactNPureComponentClass<P, S, G, R, SS> { }
134+
135+
class Component { }
115136
class ComponentClass { }
137+
class PureComponent { }
138+
class PureComponentClass { }
116139
}
117140

118-
type TypeOfReact = typeof React;
119-
120141

121142

122143
export = Object.assign(reactn, React, {

tests/components/index.test.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ const testComponent = (
2424

2525
testMount(
2626
class TestMount extends _Super<Props, {}, G, R> {
27-
render() { return null; }
27+
public render(): null { return null; }
2828
}
2929
);
3030

@@ -33,8 +33,8 @@ const testComponent = (
3333
testComponentWillUnmount(
3434
'prototype',
3535
class TestUnmountPrototype extends _Super {
36-
componentWillUnmount() { spyUnmountPrototype(); }
37-
render() { return null; }
36+
public componentWillUnmount(): void { spyUnmountPrototype(); }
37+
public render(): null { return null; }
3838
},
3939
spyUnmountPrototype,
4040
);
@@ -65,8 +65,8 @@ const testComponent = (
6565
testComponentWillUpdate(
6666
'prototype',
6767
class TestUpdatePrototype extends _Super<Props, {}, G, R> {
68-
componentWillUpdate() { spyUpdatePrototype(); }
69-
render() { return null; }
68+
public componentWillUpdate(): void { spyUpdatePrototype(); }
69+
public render(): null { return null; }
7070
},
7171
spyUpdatePrototype,
7272
);
@@ -117,7 +117,7 @@ describe('Components', (): void => {
117117
testMount(
118118
reactn(
119119
class DecoratedMount extends Component<Props, {}> {
120-
render() { return null; }
120+
public render(): null { return null; }
121121
}
122122
)
123123
);
@@ -128,8 +128,8 @@ describe('Components', (): void => {
128128
'prototype',
129129
reactn(
130130
class DecoratedCwuPrototype extends Component {
131-
componentWillUnmount() { spyUnmountPrototype(); }
132-
render() { return null; }
131+
public componentWillUnmount(): void { spyUnmountPrototype(); }
132+
public render(): null { return null; }
133133
}
134134
),
135135
spyUnmountPrototype,
@@ -165,8 +165,8 @@ describe('Components', (): void => {
165165
'prototype',
166166
reactn(
167167
class DecoratedCwuPrototype extends Component<Props, {}> {
168-
componentWillUpdate() { spyUpdatePrototype(); }
169-
render() { return null; }
168+
public componentWillUpdate(): void { spyUpdatePrototype(); }
169+
public render(): null { return null; }
170170
}
171171
),
172172
spyUpdatePrototype,

types/component-class.d.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
import { ComponentClass } from 'react';
22
import { Reducers, State } from '../default';
33
import { ReactNComponent, ReactNPureComponent } from './component';
4+
import Omit from './omit';
45

56
export interface ReactNComponentClass<
67
P extends {} = {},
78
S extends {} = {},
89
G extends {} = State,
910
R extends {} = Reducers,
1011
SS = any,
11-
> extends ComponentClass<P, S> {
12+
> extends Omit<ComponentClass<P, S>, 'constructor' | 'new'> {
1213
new (props: P, context?: any): ReactNComponent<P, S, G, R, SS>;
1314
}
1415

@@ -18,6 +19,6 @@ export interface ReactNPureComponentClass<
1819
G extends {} = State,
1920
R extends {} = Reducers,
2021
SS = any,
21-
> extends ComponentClass<P, S> {
22+
> extends Omit<ComponentClass<P, S>, 'constructor' | 'new'> {
2223
new (props: P, context?: any): ReactNPureComponent<P, S, G, R, SS>;
2324
}

types/omit.d.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
type Omit<T, K extends keyof any> = Pick<T, Exclude<keyof T, K>>;
2+
3+
export default Omit;

0 commit comments

Comments
 (0)