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

undo jsx-element removal #3680

Merged
merged 1 commit into from
Aug 19, 2022
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/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): ComponentChild;
(props: RenderableProps<P>, context?: any): VNode<any>;
Copy link

@piotr-cz piotr-cz Aug 19, 2022

Choose a reason for hiding this comment

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

This didn't revert return type to VNode<any> | null, as it was in v10.10.3

Returning null from components is valid, as described here:
React Docs > Preventing Component from Rendering

displayName?: string;
defaultProps?: Partial<P>;
}
Expand Down
1 change: 1 addition & 0 deletions src/jsx.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ export namespace JSXInternal {
: never;
}[keyof IntrinsicElements]
| ComponentType<P>;
export interface Element extends VNode<any> {}
export type ElementClass = Component<any, any> | FunctionComponent<any>;

export interface ElementAttributesProperty {
Expand Down
31 changes: 16 additions & 15 deletions test/ts/preact.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -102,21 +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>
);
}
// TODO: make this work
// 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> {
Expand Down