Skip to content

Commit

Permalink
allow function component with children (#3676)
Browse files Browse the repository at this point in the history
* allow function component with children

* test for 3611

* better element type

* remove namespace
  • Loading branch information
JoviDeCroock authored Aug 18, 2022
1 parent 1cb4b38 commit 7d54883
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ export type ComponentProps<
: never;

export interface FunctionComponent<P = {}> {
(props: RenderableProps<P>, context?: any): VNode<any> | null;
(props: RenderableProps<P>, context?: any): ComponentChild;
displayName?: string;
defaultProps?: Partial<P>;
}
Expand Down
14 changes: 11 additions & 3 deletions src/jsx.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
import {
ClassAttributes,
Component,
ComponentChild,
ComponentType,
FunctionComponent,
PreactDOMAttributes,
VNode
} from './index';
Expand All @@ -26,9 +29,14 @@ export namespace JSXInternal {
key?: any;
}

export interface Element extends VNode<any> {}

export interface ElementClass extends Component<any, any> {}
export type ElementType<P = any> =
| {
[K in keyof IntrinsicElements]: P extends IntrinsicElements[K]
? K
: never;
}[keyof IntrinsicElements]
| ComponentType<P>;
export type ElementClass = Component<any, any> | FunctionComponent<any>;

export interface ElementAttributesProperty {
props: any;
Expand Down
16 changes: 16 additions & 0 deletions test/ts/preact.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,22 @@ const UseOfComponentWithChildren = () => {
);
};

const DummyChildren: FunctionalComponent = ({ children }) => {
return children;
};

function ReturnChildren(props: { children: preact.ComponentChildren }) {
return props.children;
}

function TestUndefinedChildren() {
return (
<ReturnChildren>
<ReturnChildren>Hello</ReturnChildren>
</ReturnChildren>
);
}

// using ref and or jsx
class ComponentUsingRef extends Component<any, any> {
private array: string[];
Expand Down

0 comments on commit 7d54883

Please sign in to comment.