Skip to content

Commit

Permalink
Merge pull request #1219 from KasparEtter/component-children
Browse files Browse the repository at this point in the history
Add boolean to ComponentChild in preact.d.ts and remove object from type
  • Loading branch information
marvinhagemeister authored Oct 1, 2018
2 parents b7038d1 + 884cf7d commit 8b2f56a
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 6 deletions.
4 changes: 2 additions & 2 deletions src/preact.d.ts
Original file line number Diff line number Diff line change
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;
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
Original file line number Diff line number Diff line change
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>;

0 comments on commit 8b2f56a

Please sign in to comment.