Reduce the use of `@ts-expect-error`
Unanswered
Asian paper wasp posted this in #help-forum
Asian paper waspOP
In my blog page, I used more
Here's the full code: https://github.com/mwskwong/resume/blob/feature/blog/app/blog/%5Bslug%5D/page.tsx
A short summary:
1. The
2. The
@ts-expect-error than I would have liked to due to various reasons, I wonder if I can define the type better and reduce the use of @ts-expect-error, as that's a bit too hacky.Here's the full code: https://github.com/mwskwong/resume/blob/feature/blog/app/blog/%5Bslug%5D/page.tsx
A short summary:
1. The
data-* props are not defined in the prop type.2. The
ref prop is in type LegacyRef while my components (MUI in this case) expects to be RefObject.<MDXRemote
components={{
code: (props) => {
// @ts-expect-error (1) data attribute auto injected by rehype-pretty-code
const inlineCode = !props["data-language"];
if (inlineCode) {
const { color, ...rest } = props;
return (
// @ts-expect-error (2) LegacyRef passed to RefObject
<Typography {/* props omitted... */} {...rest} />
);
}
// @ts-expect-error (2) LegacyRef passed to RefObject
return <Box {/* props omitted... */} {...props} />;
},
}}
/>2 Replies
Asian paper waspOP
Bump
Feel free to use
and for the
as if you know what you are doing, for example: props as PrettyCodePropsand for the
ref, normally it's not required. You may remove ref by extracting it out: {ref, ...props}