Skip to content

Commit

Permalink
Improve typing (#1616)
Browse files Browse the repository at this point in the history
* sync types.ts and components.ts

* Improve ref typing in refs.ts and types.ts (have I understood this correct?)

* Revert "Improve ref typing in refs.ts and types.ts (have I understood this correct?)"

This reverts commit 62a5cfa.

* Fix type error in inferno-redux
  • Loading branch information
jhsware authored Nov 13, 2022
1 parent e3c3deb commit f606368
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 9 deletions.
4 changes: 2 additions & 2 deletions packages/inferno-redux/src/components/Provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export interface Props<A extends Action = AnyAction> {
children?: Inferno.InfernoNode;
}

export class Provider<A extends Action = AnyAction> extends Component<Props<A>, null> {
export class Provider<A extends Action = AnyAction> extends Component<Props<A>> {
public static displayName = 'Provider';
private readonly store: Store<any, A>;

Expand All @@ -37,7 +37,7 @@ export class Provider<A extends Action = AnyAction> extends Component<Props<A>,
return this.props.children;
}

public componentWillReceiveProps?(nextProps: Props<A>, nextContext: any): void;
public componentWillReceiveProps?(nextProps: Readonly<{ children?: Inferno.InfernoNode } & Props<A>>, nextContext: any): void;
}

if (process.env.NODE_ENV !== 'production') {
Expand Down
10 changes: 8 additions & 2 deletions packages/inferno/src/core/component.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { Inferno } from './types';
import { IComponent } from './types';
import { IComponent, VNode } from './types';
import { combineFrom, isFunction, isNullOrUndef, throwError } from 'inferno-shared';
import { updateClassComponent } from '../DOM/patching';
import { AnimationQueues, callAll, callAllAnimationHooks, EMPTY_OBJ, findDOMFromVNode, renderCheck } from '../DOM/utils/common';
Expand Down Expand Up @@ -158,7 +158,7 @@ export abstract class Component<P = {}, S = {}> implements IComponent<P, S> {
}

public setState<K extends keyof S>(
newState: ((prevState: Readonly<S>, props: Readonly<P>) => Pick<S, K> | S | null) | (Pick<S, K> | S | null),
newState: ((prevState: Readonly<S>, props: Readonly<{ children?: Inferno.InfernoNode } & P>) => Pick<S, K> | S | null) | (Pick<S, K> | S | null),
callback?: () => void
): void {
if (this.$UN) {
Expand Down Expand Up @@ -188,6 +188,12 @@ export abstract class Component<P = {}, S = {}> implements IComponent<P, S> {

public componentWillUnmount?(): void;

public componentDidAppear?(domNode: Element): void;

public componentWillDisappear?(domNode: Element, callback: Function): void;

public componentWillMove?(parentVNode: VNode, parentDOM: Element, dom: Element): void;

public getChildContext?(): void;

public getSnapshotBeforeUpdate?(prevProps: Readonly<{ children?: Inferno.InfernoNode } & P>, prevState: Readonly<S>): any;
Expand Down
10 changes: 5 additions & 5 deletions packages/inferno/src/core/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,11 @@ export interface IComponent<P, S> {

componentWillReceiveProps?(nextProps: Readonly<{ children?: Inferno.InfernoNode } & P>, nextContext: any): void;

shouldComponentUpdate?(nextProps: Readonly<{ children?: Inferno.InfernoNode } & P>, nextState: S, context: any): boolean;
shouldComponentUpdate?(nextProps: Readonly<{ children?: Inferno.InfernoNode } & P>, nextState: Readonly<S>, context: any): boolean;

componentWillUpdate?(nextProps: Readonly<{ children?: Inferno.InfernoNode } & P>, nextState: S, context: any): void;
componentWillUpdate?(nextProps: Readonly<{ children?: Inferno.InfernoNode } & P>, nextState: Readonly<S>, context: any): void;

componentDidUpdate?(prevProps: Readonly<{ children?: Inferno.InfernoNode } & P>, prevState: S, snapshot: any): void;
componentDidUpdate?(prevProps: Readonly<{ children?: Inferno.InfernoNode } & P>, prevState: Readonly<S>, snapshot: any): void;

componentWillUnmount?(): void;

Expand All @@ -49,9 +49,9 @@ export interface IComponent<P, S> {

getChildContext?(): void;

getSnapshotBeforeUpdate?(prevProps: Readonly<{ children?: Inferno.InfernoNode } & P>, prevState: S): any;
getSnapshotBeforeUpdate?(prevProps: Readonly<{ children?: Inferno.InfernoNode } & P>, prevState: Readonly<S>): any;

render(nextProps: Readonly<{ children?: Inferno.InfernoNode } & P>, nextState: S, nextContext: any): Inferno.InfernoNode;
render(nextProps: Readonly<{ children?: Inferno.InfernoNode } & P>, nextState: Readonly<S>, nextContext: any): Inferno.InfernoNode;
}

export interface SemiSyntheticEvent<T> extends Event {
Expand Down

0 comments on commit f606368

Please sign in to comment.