Skip to content
This repository has been archived by the owner on Dec 31, 2020. It is now read-only.

Commit

Permalink
Merge pull request #193 from tkrotoff/observer-void
Browse files Browse the repository at this point in the history
Allow Component<void, void>
  • Loading branch information
mweststrate committed Jan 17, 2017
2 parents 7a47420 + 63be8ad commit 20bdcb3
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 7 deletions.
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -49,7 +49,7 @@
"tap-spec": "^4.1.1",
"tape": "^4.2.2",
"tape-run": "2.1.0",
"typescript": "^1.8.10",
"typescript": "^2.1.4",
"webpack": "^1.13.1"
},
"dependencies": {
Expand Down
2 changes: 1 addition & 1 deletion src/index.d.ts
Expand Up @@ -8,7 +8,7 @@ export type IReactComponent<P> = React.StatelessComponent<P> | React.ComponentCl

export function observer<P>(clazz: IReactComponent<P>): React.ClassicComponentClass<P>;
export function observer<P>(clazz: React.ClassicComponentClass<P>): React.ClassicComponentClass<P>;
export function observer<P, TFunction extends React.ComponentClass<P>>(target: TFunction): TFunction; // decorator signature
export function observer<P, TFunction extends React.ComponentClass<P | void>>(target: TFunction): TFunction; // decorator signature

export function inject<P>(...stores: string[]): <TFunction extends IReactComponent<P>>(target: TFunction) => TFunction; // decorator signature
export function inject<T, P>(storesToProps : IStoresToProps<T, P>): <TFunction extends IReactComponent<T | P>>(target: TFunction) => TFunction; // decorator
Expand Down
18 changes: 14 additions & 4 deletions test/ts/compile-ts.tsx
Expand Up @@ -23,10 +23,10 @@ const T2 = observer(React.createClass({
}));

const T3 = observer((props: { hamburger: number }) => {
return <T2 cake={this.props.hamburger} />;
return <T2 cake={props.hamburger} />;
});

const T4 = ({sandwich}: { sandwich: number }) => <div><T3 hamburger={this.props.sandwich} /></div>;
const T4 = ({sandwich}: { sandwich: number }) => <div><T3 hamburger={sandwich} /></div>;

const T5 = observer(() => {
return <T3 hamburger={17} />;
Expand Down Expand Up @@ -75,7 +75,7 @@ const T9 = observer(["stores"], React.createClass({
}));

const T10 = observer(["stores"], (props: { hamburger: number }) => {
return <T2 cake={this.props.hamburger} />;
return <T2 cake={props.hamburger} />;
});

React.createElement(observer(T8), { pizza: 4 });
Expand All @@ -102,7 +102,7 @@ class T15 extends Component<{ pizza: number, x?: number }, {}> {
}
const T16 = inject(() => ({ x: 3 }))(T15);

class T17 extends React.Component<{}, {}> {
class T17 extends Component<{}, {}> {
render() {
return <div>
<T11 pizza={3} x={1} />
Expand Down Expand Up @@ -151,3 +151,13 @@ class ObserverTest extends Component<any, any> {
return <Observer>{() => <div>test</div>}</Observer>;
}
}

@observer
class ComponentWithoutPropsAndState extends Component<void, void> {
componentDidUpdate() {
}

render() {
return (<div>Hello!</div>)
}
}
4 changes: 3 additions & 1 deletion test/ts/tsconfig.json
Expand Up @@ -3,13 +3,15 @@
"compilerOptions": {
"target": "es5",
"noImplicitAny": true,
"noImplicitThis": false,
"strictNullChecks": true,
"experimentalDecorators": true,
"jsx": "react",
"noEmit": true,
"rootDir": "../../",
"module": "commonjs"
},
"exclude": [

]
}

0 comments on commit 20bdcb3

Please sign in to comment.