Skip to content

Commit

Permalink
Update type definition (#1581)
Browse files Browse the repository at this point in the history
  • Loading branch information
38elements authored and marvinhagemeister committed Apr 28, 2019
1 parent 5cac157 commit 47656bc
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/create-element.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ export /* istanbul ignore next */ function Fragment() { }
* Specifically, this should be used anywhere a user could provide a boolean, string, or number where
* a VNode or Component is desired instead
* @param {boolean | string | number | import('./internal').VNode} possibleVNode A possible VNode
* @returns {import('./internal').VNode}
* @returns {import('./internal').VNode | null}
*/
export function coerceToVNode(possibleVNode) {
if (possibleVNode == null || typeof possibleVNode === 'boolean') return null;
Expand Down
2 changes: 1 addition & 1 deletion src/diff/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import options from '../options';
* mounted components
* @param {import('../internal').Component | null} ancestorComponent The direct
* parent component
* @param {Node | Text} oldDom The current attached DOM
* @param {Element | Text} oldDom The current attached DOM
* element any new dom elements should be placed around. Likely `null` on first
* render (except when hydrating). Can be a sibling DOM element when diffing
* Fragments that have siblings. In most cases, it starts out as `oldChildren[0]._dom`.
Expand Down
10 changes: 7 additions & 3 deletions src/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ declare namespace preact {
state: Readonly<S>;
props: RenderableProps<P>;
context: any;
base?: HTMLElement;
base?: Element | Text;

// From https://github.com/DefinitelyTyped/DefinitelyTyped/blob/e836acc75a78cf0655b5dfdbe81d69fdd4d8a252/types/react/index.d.ts#L402
// // We MUST keep setState() as a unified signature because it allows proper checking of the method return type.
Expand Down Expand Up @@ -160,8 +160,12 @@ declare namespace preact {
// Preact render
// -----------------------------------

function render(vnode: ComponentChild, parent: Element | Document | ShadowRoot | DocumentFragment): void
function hydrate(vnode: ComponentChild, parent: Element | Document | ShadowRoot | DocumentFragment): void
function render(
vnode: ComponentChild,
parent: Element | Document | ShadowRoot | DocumentFragment,
replaceNode?: Element | Text
): void;
function hydrate(vnode: ComponentChild, parent: Element | Document | ShadowRoot | DocumentFragment): void;
function cloneElement(vnode: JSX.Element, props: any, ...children: ComponentChildren[]): JSX.Element;

//
Expand Down
1 change: 1 addition & 0 deletions src/internal.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export interface PreactElement extends HTMLElement {
export interface VNode<P = {}> extends preact.VNode<P> {
// Redefine type here using our internal ComponentFactory type
type: string | ComponentFactory<P> | null;
_self: this;
_children: Array<VNode> | null;
/**
* The [first (for Fragments)] DOM child of a VNode
Expand Down
2 changes: 1 addition & 1 deletion src/render.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import options from './options';
* @param {import('./index').ComponentChild} vnode The virtual node to render
* @param {import('./internal').PreactElement} parentDom The DOM element to
* render into
* @param {import('./dom').PreactElement} [replaceNode] Attempt to re-use an
* @param {Element | Text} [replaceNode] Attempt to re-use an
* existing DOM tree rooted at `replaceNode`
*/
export function render(vnode, parentDom, replaceNode) {
Expand Down

0 comments on commit 47656bc

Please sign in to comment.