-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
Fix up compat types and tests #1740
Changes from all commits
6236964
57ec91a
c3742a9
523bd1f
a337a68
29919b8
39ad42d
b7ab1d8
3d8c302
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -53,11 +53,11 @@ declare namespace React { | |
|
||
export function unmountComponentAtNode(container: Element | Document | ShadowRoot | DocumentFragment): boolean; | ||
|
||
export function createFactory(type: preact.VNode["type"]): preact.VNode<{}>; | ||
export function createFactory(type: preact.VNode<any>["type"]): (props?: any, ...children: preact.ComponentChildren[]) => preact.VNode<any>; | ||
export function isValidElement(element: any): boolean; | ||
export function findDOMNode(component: preact.Component): Element | null; | ||
|
||
export interface PureComponent<P = {}, S = {}> extends preact.Component { | ||
export class PureComponent<P = {}, S = {}> extends preact.Component { | ||
isPureReactComponenet: boolean; | ||
} | ||
|
||
|
@@ -67,7 +67,7 @@ declare namespace React { | |
|
||
export function unstable_batchedUpdates(callback: (arg?: any) => void, arg?: any): void; | ||
|
||
export interface Children { | ||
export const Children: { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Updating the type to be a real object, not an interface for some other object to implement |
||
map<T extends preact.ComponentChild, R>(children: T | T[], fn: (child: T, i: number, array: T[]) => R): R[]; | ||
forEach<T extends preact.ComponentChild>(children: T | T[], fn: (child: T, i: number, array: T[]) => void): void; | ||
count: (children: preact.ComponentChildren) => number; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,6 @@ | ||
import { hydrate, render as preactRender, cloneElement as preactCloneElement, createRef, h, Component, options, toChildArray, createContext, Fragment } from 'preact'; | ||
import * as hooks from 'preact/hooks'; | ||
export * from 'preact/hooks'; | ||
import { Suspense as _Suspense, lazy as _lazy, catchRender } from './suspense'; | ||
import { Suspense, lazy, catchRender } from './suspense'; | ||
import { assign, removeNode } from '../../src/util'; | ||
|
||
const version = '16.8.0'; // trick libraries to think we are react | ||
|
@@ -174,12 +173,11 @@ function normalizeVNode(vnode) { | |
* all vnode normalizations. | ||
* @param {import('./internal').VNode} element The vnode to clone | ||
* @param {object} props Props to add when cloning | ||
* @param {Array<import('./internal').ComponentChildren} rest Optional component children | ||
* @param {Array<import('./internal').ComponentChildren>} rest Optional component children | ||
*/ | ||
function cloneElement(element) { | ||
if (!isValidElement(element)) return element; | ||
let vnode = normalizeVNode(preactCloneElement.apply(null, arguments)); | ||
vnode.$$typeof = REACT_ELEMENT_TYPE; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is already set in |
||
return vnode; | ||
} | ||
|
||
|
@@ -222,7 +220,7 @@ function applyEventNormalization({ type, props }) { | |
|
||
/** | ||
* Remove a component tree from the DOM, including state and event handlers. | ||
* @param {Element | Document | ShadowRoot | DocumentFragment} container | ||
* @param {import('./internal').PreactElement} container | ||
* @returns {boolean} | ||
*/ | ||
function unmountComponentAtNode(container) { | ||
|
@@ -287,7 +285,7 @@ class PureComponent extends Component { | |
} | ||
} | ||
|
||
// Some libraries like `react-virtualized` explicitely check for this. | ||
// Some libraries like `react-virtualized` explicitly check for this. | ||
Component.prototype.isReactComponent = {}; | ||
|
||
/** | ||
|
@@ -366,14 +364,14 @@ options.vnode = vnode => { | |
/** | ||
* Deprecated way to control batched rendering inside the reconciler, but we | ||
* already schedule in batches inside our rendering code | ||
* @param {(a) => void} callback function that triggers the updatd | ||
* @param {*} [arg] Optional argument that can be passed to the callback | ||
* @template Arg | ||
* @param {(arg: Arg) => void} callback function that triggers the updated | ||
* @param {Arg} [arg] Optional argument that can be passed to the callback | ||
*/ | ||
// eslint-disable-next-line camelcase | ||
function unstable_batchedUpdates(callback, arg) { | ||
callback(arg); | ||
} | ||
const unstable_batchedUpdates = (callback, arg) => callback(arg); | ||
|
||
export * from 'preact/hooks'; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Moved all exports to the bottom of the file so they are grouped together |
||
export { | ||
version, | ||
Children, | ||
|
@@ -394,12 +392,11 @@ export { | |
memo, | ||
forwardRef, | ||
// eslint-disable-next-line camelcase | ||
unstable_batchedUpdates | ||
unstable_batchedUpdates, | ||
Suspense, | ||
lazy | ||
}; | ||
|
||
export const Suspense = _Suspense; | ||
export const lazy = _lazy; | ||
|
||
// React copies the named exports to the default one. | ||
export default assign({ | ||
version, | ||
|
@@ -420,5 +417,7 @@ export default assign({ | |
PureComponent, | ||
memo, | ||
forwardRef, | ||
unstable_batchedUpdates | ||
unstable_batchedUpdates, | ||
Suspense, | ||
lazy | ||
}, hooks); |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,7 +19,7 @@ export interface Component<P = {}, S = {}> extends PreactComponent<P, S> { | |
|
||
export interface FunctionalComponent<P = {}> extends PreactFunctionalComponent<P> { | ||
shouldComponentUpdate?(nextProps: Readonly<P>): boolean; | ||
_forwarded?: true; | ||
_forwarded?: boolean; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Makes VSCode happier when used in |
||
} | ||
|
||
export interface VNode<T = any> extends PreactVNode<T> { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,4 +10,4 @@ export interface SuspenseProps { | |
fallback: preact.ComponentChildren; | ||
} | ||
|
||
export abstract class Suspense extends Component<SuspenseProps> {} | ||
export class Suspense extends Component<SuspenseProps> {} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Suspense isn't supposed to be extended so removed the abstract keyword |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PureComponent
is an actual class that should be extended by other classes, not an interface that any object implement