Skip to content

Commit

Permalink
Use IComponent interface to declare Component JSX types instead of im…
Browse files Browse the repository at this point in the history
…plementation type to allow mixing usages with React application. Fixes Github #1599
  • Loading branch information
Sampo Kivistö committed Jun 19, 2022
1 parent 5e7e804 commit 5192eef
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions packages/inferno/src/core/types.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import type { NativeClipboardEvent, NativeCompositionEvent, NativeDragEvent, NativeFocusEvent } from './nativetypes';
import { ChildFlags, VNodeFlags } from 'inferno-vnode-flags';
import { Component } from './component';

export interface LinkedEvent<T, E extends Event> {
data: T;
Expand Down Expand Up @@ -179,8 +178,8 @@ export declare namespace Inferno {
type: SFC<P>;
}

type CElement<P, T extends Component<P, ComponentState>> = ComponentElement<P, T>;
interface ComponentElement<P, T extends Component<P, ComponentState>> extends InfernoElement<P> {
type CElement<P, T extends IComponent<P, ComponentState>> = ComponentElement<P, T>;
interface ComponentElement<P, T extends IComponent<P, ComponentState>> extends InfernoElement<P> {
type: ComponentClass<P>;
ref?: Ref<T> | undefined;
}
Expand Down Expand Up @@ -213,9 +212,9 @@ export declare namespace Inferno {

type SFCFactory<P> = (props?: Attributes & P, ...children: InfernoNode[]) => SFCElement<P>;

type ComponentFactory<P, T extends Component<P, ComponentState>> = (props?: ClassAttributes<T> & P, ...children: InfernoNode[]) => CElement<P, T>;
type ComponentFactory<P, T extends IComponent<P, ComponentState>> = (props?: ClassAttributes<T> & P, ...children: InfernoNode[]) => CElement<P, T>;

type CFactory<P, T extends Component<P, ComponentState>> = ComponentFactory<P, T>;
type CFactory<P, T extends IComponent<P, ComponentState>> = ComponentFactory<P, T>;
type ClassicFactory<P> = CFactory<P, ClassicComponent<P, ComponentState>>;

type DOMFactory<P extends DOMAttributes<T>, T extends Element> = (props?: (ClassAttributes<T> & P) | null, ...children: InfernoNode[]) => DOMElement<P, T>;
Expand Down Expand Up @@ -248,7 +247,7 @@ export declare namespace Inferno {
// Component API
// ----------------------------------------------------------------------

interface ClassicComponent<P = {}, S = {}> extends Component<P, S> {
interface ClassicComponent<P = {}, S = {}> extends IComponent<P, S> {
replaceState(nextState: S, callback?: () => any): void;
isMounted(): boolean;
getInitialState?(): S;
Expand All @@ -270,7 +269,7 @@ export declare namespace Inferno {
}

interface ComponentClass<P = {}> {
new (props?: P, context?: any): Component<P, ComponentState>;
new (props?: P, context?: any): IComponent<P, ComponentState>;
defaultProps?: Partial<P> | undefined;
}

Expand Down Expand Up @@ -1789,7 +1788,7 @@ declare global {
namespace JSX {
// tslint:disable-next-line:no-empty-interface
type Element = Inferno.InfernoElement<any> | string | number;
interface ElementClass extends Component<any, any> {
interface ElementClass extends IComponent<any, any> {
render(nextProps, nextState, nextContext): Inferno.InfernoNode;
}
interface ElementAttributesProperty {
Expand Down

0 comments on commit 5192eef

Please sign in to comment.