Skip to content

Commit

Permalink
add Partial typing to setState
Browse files Browse the repository at this point in the history
this is not strict enough for strictNullChecks
see: microsoft/TypeScript#12793
  • Loading branch information
yihongang committed Jun 26, 2017
1 parent ac7194b commit fb4b2a9
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions packages/inferno-component/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,9 @@ function applyState<P, S>(component: Component<P, S>, force: boolean, callback?:

let alreadyWarned = false;

export type StateFn<P, S> = (prevState: S | null, props: P, context: any) => Partial<S>
export type StateArg<P, S> = StateFn<P, S> | Partial<S>

export default class Component<P, S> implements ComponentLifecycle<P, S> {
public static defaultProps: {};
public state: S|null = null;
Expand Down Expand Up @@ -243,7 +246,7 @@ export default class Component<P, S> implements ComponentLifecycle<P, S> {
applyState(this, true, callback);
}

public setState(newState, callback?: Function) {
public setState(newState: StateArg<P, S>, callback?: Function) {
if (this._unmounted) {
return;
}
Expand All @@ -257,7 +260,7 @@ export default class Component<P, S> implements ComponentLifecycle<P, S> {
}
}

public setStateSync(newState) {
public setStateSync(newState: StateArg<P, S>) {
if (process.env.NODE_ENV !== 'production') {
if (!alreadyWarned) {
alreadyWarned = true;
Expand Down

0 comments on commit fb4b2a9

Please sign in to comment.