Skip to content

Commit fb4b2a9

Browse files
committed
add Partial typing to setState
this is not strict enough for strictNullChecks see: microsoft/TypeScript#12793
1 parent ac7194b commit fb4b2a9

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

packages/inferno-component/src/index.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,9 @@ function applyState<P, S>(component: Component<P, S>, force: boolean, callback?:
193193

194194
let alreadyWarned = false;
195195

196+
export type StateFn<P, S> = (prevState: S | null, props: P, context: any) => Partial<S>
197+
export type StateArg<P, S> = StateFn<P, S> | Partial<S>
198+
196199
export default class Component<P, S> implements ComponentLifecycle<P, S> {
197200
public static defaultProps: {};
198201
public state: S|null = null;
@@ -243,7 +246,7 @@ export default class Component<P, S> implements ComponentLifecycle<P, S> {
243246
applyState(this, true, callback);
244247
}
245248

246-
public setState(newState, callback?: Function) {
249+
public setState(newState: StateArg<P, S>, callback?: Function) {
247250
if (this._unmounted) {
248251
return;
249252
}
@@ -257,7 +260,7 @@ export default class Component<P, S> implements ComponentLifecycle<P, S> {
257260
}
258261
}
259262

260-
public setStateSync(newState) {
263+
public setStateSync(newState: StateArg<P, S>) {
261264
if (process.env.NODE_ENV !== 'production') {
262265
if (!alreadyWarned) {
263266
alreadyWarned = true;

0 commit comments

Comments
 (0)