-
Notifications
You must be signed in to change notification settings - Fork 103
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
Typescript compilation issues #291
Comments
Can you confirm that you are on the latest version? And which version of
react you are using?
|
I'm running version |
Hopefully. Please upgrade to 2.2.0 and see if that sorts it out?
|
The problem still seems to persist |
I'am experiencing this as well.
Here is some extract from my code how i have it setup. In case i misunderstood something about this. import React from "react";
import { isMobile } from "react-device-detect";
import { Link as RouterLink } from "react-router-dom";
import { colorNormal } from "./Styling";
import JsxParser from "react-jsx-parser";
interface LinkProps {
children?: React.ReactNode | string;
tooltip?: string;
to: string;
style?: React.CSSProperties;
}
export function Link({ children, ...props }: LinkProps) {
const useTooltip = !isMobile && props.tooltip;
return (
<>
{useTooltip && <Tooltip id="linkTooltip" />}
<RouterLink
data-tooltip-id={useTooltip ? "linkTooltip" : undefined}
data-tooltip-content={useTooltip ? props.tooltip : undefined}
data-tooltip-place={useTooltip ? "top" : undefined}
to={props.to}
rel="noopener noreferrer"
style={{
color: colorNormal,
...props.style,
}}
>
{children}
</RouterLink>
</>
);
}
export const handleText = (text: string) => {
const jsx = <JsxParser components={{ Link }} jsx={text} />;
return jsx;
}; From a render function: export default Character;
function Page() {
const description = [
"Nulla non mauris mauris. Mauris vel maximus turpis.",
'Sed rutrum urna quis ligula <Link to="/somewhere/here">egestas<Link>, a gravida justo venenatis.',
'Phasellus sed tempus enim. In non malesuada tortor, sed <Link to="/somewhere/other">ullamcorper massa<Link>.',
];
return (
<>
{description ? (
description.map((body) => (
<Text key={"body"}>{handleText(description.toString())}</Text>
))
) : (
<Text>No information given.</Text>
)}
</>
);
} |
@AndreasBrostrom I'm not 100% sure — but I believe the issue is that your system is interpreting the output of your component as It may help for the lib to allow for that as an alternative signature for components, but in the meantime, can you please change your code to: export const Link = React.FC<LinkProps>({ children, ...props }) => { The return <>
{/* all your stuff */}
</> as React.ReactNode and see if that addresses the coersion? Finally, you can easily get around this as a workaround by simply adding: // @ts-expect-error - incorrectly inferred return type Right above the offending line. |
I attempted to expand the allowable signatures for components in the version I just pushed. Please pull latest and let me know if this resolves? |
Same issue. Repro here: TS Playground Could make the type |
I tried with 2.2.2 and the issue still persists. |
I am getting some typescript issues that are a bit difficult to resolve when trying to override the components in the JSXParser
components
map prop. Sample code below:I seem to be getting this error:
Is there a way to extend (or override) the types provided for the
JSXParser
component to fix these errors.The text was updated successfully, but these errors were encountered: