Repository navigation
Description
π Search Terms
declaration emit inline
π Version & Regression Information
I was unable to test this prior to 4.4 since React types are no longer compatible with that version.
β― Playground Link
No response
π» Code
import * as React from "react";
export class Component extends React.Component<{ children: React.ReactNode }> {
render() {
if (Math.random()) {
return <div>{this.props.children}</div>;
} else {
return this.props.children;
}
}
}π Actual behavior
Return value from render() is not referencing React.ReactNode but inlines its (incomplete) union members:
import * as React from "react";
export declare class Component extends React.Component<{
children: React.ReactNode;
}> {
render(): string | number | boolean | Iterable<React.ReactNode> | import("react/jsx-runtime").JSX.Element;
}π Expected behavior
Return type references the type alias. Inlining union members is incorrect (we may add or remove members or treat members as internal, local types) generally and here specially not even using all members.
export declare class Component extends React.Component<{
children: React.ReactNode;
}> {
render(): React.ReactNode | import("react/jsx-runtime").JSX.Element;
}Additional information about the issue
The fact that it inlines the type here is a special case of #37151. #37151 is a more general since it's not always clear when inlining is correct or not. I'd be curious to know what would break if TS would not stop inlining in this special case.
But this issue is also broader since the inline is incomplete.
Activity
RyanCavanaugh commentedon Mar 15, 2024
What's incomplete about this? I don't see any missing things in the union
eps1lon commentedon Mar 15, 2024
React.ReactElementis not the same asReact.JSX.Elementsince they're different interfaces.But that's not the focus here. The problem is that TypeScript inlines in the first place here. Especially because the same version of the published types can have different versions of
ReactNodedue to module augmentation.[link] Avoid inlining of `LinkProps` in emitted declarations (#78773)