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

Update type definition #1581

Merged
merged 1 commit into from
Apr 28, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Copy link
Contributor Author

Choose a reason for hiding this comment

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

): 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;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

_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