What happens
Tooltip's content is typed string, but the implementation renders it straight through as the
children of Tooltip.Popup:
export interface TooltipProps {
content?: string;
...
}
jsx(Tooltip$1.Popup, { className: "cratis-tooltip-popup", children: content })
So any ReactNode renders correctly at runtime - the type is simply narrower than the component.
Why it matters
Help content is the natural case: a tooltip holding a couple of paragraphs and a "Learn more" link
is ordinary, and it works today - but only if you cast:
<Tooltip content={help as unknown as string} position='right'>
That cast is not describing anything true, and it silences the compiler for the whole expression,
so a genuine mistake in help would no longer be caught. A consumer that does not want the cast has
to either flatten rich help into a string or stop using the wrapper, which is the thing the wrapper
exists to prevent (primereact/tooltip directly).
Suggested
Widen to content?: React.ReactNode. It matches what the component already does, is source-compatible
for every existing call site (string is a ReactNode), and needs no runtime change.
Observed on @cratis/components as resolved in an application today; worked around locally with the
cast above, referencing this issue.
What happens
Tooltip'scontentis typedstring, but the implementation renders it straight through as thechildren of
Tooltip.Popup:So any
ReactNoderenders correctly at runtime - the type is simply narrower than the component.Why it matters
Help content is the natural case: a tooltip holding a couple of paragraphs and a "Learn more" link
is ordinary, and it works today - but only if you cast:
That cast is not describing anything true, and it silences the compiler for the whole expression,
so a genuine mistake in
helpwould no longer be caught. A consumer that does not want the cast hasto either flatten rich help into a string or stop using the wrapper, which is the thing the wrapper
exists to prevent (
primereact/tooltipdirectly).Suggested
Widen to
content?: React.ReactNode. It matches what the component already does, is source-compatiblefor every existing call site (
stringis aReactNode), and needs no runtime change.Observed on
@cratis/componentsas resolved in an application today; worked around locally with thecast above, referencing this issue.