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

Add boolean to ComponentChild in preact.d.ts and remove object from type #1219

Merged
merged 2 commits into from Oct 1, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/preact.d.ts
Expand Up @@ -4,8 +4,8 @@ export as namespace preact;
declare namespace preact {
type Key = string | number;
type Ref<T> = (instance: T) => void;
type ComponentChild = VNode<any> | string | number | null;
type ComponentChildren = ComponentChild[] | ComponentChild | object | string | number | null;
marvinhagemeister marked this conversation as resolved.
Show resolved Hide resolved
type ComponentChild = VNode<any> | object | string | number | boolean | null;
type ComponentChildren = ComponentChild[] | ComponentChild;

/**
* @deprecated
Expand Down
37 changes: 33 additions & 4 deletions test/ts/VNode-test.tsx
Expand Up @@ -5,7 +5,6 @@ import {
Component,
FunctionalComponent,
ComponentConstructor,
VNode
} from "../../src/preact";

class SimpleComponent extends Component<{}, {}> {
Expand Down Expand Up @@ -58,8 +57,38 @@ describe("VNode", () => {
});
});

class TypedChildren extends Component<{children: (num: number) => string}> {
render() { return null }
class ComponentWithFunctionChild extends Component<{ children: (num: number) => string; }> {
render() { return null; }
}

const typedChild = <TypedChildren>{num => num.toFixed(2)}</TypedChildren>
<ComponentWithFunctionChild>{num => num.toFixed(2)}</ComponentWithFunctionChild>;

class ComponentWithStringChild extends Component<{ children: string; }> {
render() { return null; }
}

<ComponentWithStringChild>child</ComponentWithStringChild>;

class ComponentWithNumberChild extends Component<{ children: number; }> {
render() { return null; }
}

<ComponentWithNumberChild>{1}</ComponentWithNumberChild>;

class ComponentWithBooleanChild extends Component<{ children: boolean; }> {
render() { return null; }
}

<ComponentWithBooleanChild>{false}</ComponentWithBooleanChild>;

class ComponentWithNullChild extends Component<{ children: null; }> {
render() { return null; }
}

<ComponentWithNullChild>{null}</ComponentWithNullChild>;

class ComponentWithNumberChildren extends Component<{ children: number[]; }> {
render() { return null; }
}

<ComponentWithNumberChildren>{1}{2}</ComponentWithNumberChildren>;