Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve react typescript compatibility #2329

Open
wants to merge 10 commits into
base: main
Choose a base branch
from
19 changes: 17 additions & 2 deletions compat/src/index.d.ts
@@ -1,6 +1,6 @@
import * as _hooks from '../../hooks';
import * as preact from '../../src';
import { JSXInternal } from '../../src/jsx';
import * as JSXInternal from './jsx';
import * as _Suspense from './suspense';

// export default React;
Expand Down Expand Up @@ -30,9 +30,23 @@ declare namespace React {
export import useState = _hooks.useState;

// Preact Defaults
export import Component = preact.Component;
export interface Component<P = {}, S = {}, SS = any> extends preact.Component<P, S> {}
export abstract class Component<P, S> extends preact.Component<P, S> {}
export interface ReactElement<P = {}, S = any> extends preact.VNode<P> {}
export import ComponentClass = preact.ComponentClass;
export import ComponentType = preact.ComponentType;
export import JSXElementConstructor = preact.AnyComponent;
export import Attributes = preact.Attributes;
export import ClassAttributes = preact.ClassAttributes;
export import Context = preact.Context;
export import Provider = preact.Provider;
export import ReactNode = preact.ComponentChildren;
export import ComponentPropsWithRef = preact.RenderableProps;
export type CSSProperties = string | {[key: string]: string | number};
export interface AllHTMLAttributes<T> extends JSX.HTMLAttributes {}
export import FunctionComponent = preact.FunctionComponent;
export import FC = preact.FunctionComponent;
export import SFC = preact.FunctionComponent;
export import createContext = preact.createContext;
export import createRef = preact.createRef;
export import Fragment = preact.Fragment;
Expand Down Expand Up @@ -119,4 +133,5 @@ declare namespace React {
only: (children: preact.ComponentChildren) => preact.ComponentChild;
toArray: (children: preact.ComponentChildren) => preact.VNode<{}>[];
};

}
4 changes: 4 additions & 0 deletions compat/src/jsx.d.ts
@@ -0,0 +1,4 @@
import { JSXInternal } from '../../src/jsx';

export = JSXInternal;
export as namespace JSX;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this broke typescript before

preactjs/preact-cli#1030

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In what way? I skimmed through the referenced issue but did not understand how this breaks typescript. This file declares the JSX namespace, without which, typescript does not process jsx. This is also the same way react itself exports the JSX namespace