I am trying to port https://github.com/catalinmiron/react-typical to TypeScript. However, I am facing some issues.
Here's the screenshot with errors in VSCode:
Here's the same code for brevity:
import React from 'react'
import { type, type as loopedType } from '@camwiegert/typical'
import styles from './styles.module.css'
type Props = {
steps: Array<any>
loop: number
className: string
wrapper: React.Component
}
const Typical: React.FC<Props> = ({ steps, loop, className, wrapper = 'p' }) => {
const typicalRef = React.useRef<HTMLElement>(null)
const Component: string = wrapper
const classNames: string[] = [styles.typicalWrapper]
if (className) {
classNames.unshift(className)
}
React.useEffect(() => {
if (loop === Infinity) {
type(typicalRef.current, ...steps, loopedType)
} else if (typeof loop === 'number') {
type(typicalRef.current, ...Array(loop).fill(steps).flat())
} else {
type(typicalRef.current, ...steps)
}
}, [typicalRef])
return <Component ref={typicalRef} className={classNames.join(' ')} />
}
export default React.memo(Typical)
I am unable to write type for Component.
I tried doing the following too:
const Component = React.Component | string
But it says 'Component' refers to a value, but is being used as a type here. Did you mean 'typeof Component'? near return <Component .../> with underline over Component.
I am also unable to convert the typicalRef as typicalRef.current always throws error by showing red squiggly lines under it. Same thing with flat() as well as classNames.join(' ').
I am losing my brain over it. Can't seem to figure it out. Would love any pointers?

// @ts-ignoreabove the lines (although you should try to fix them, of course).const Component = React.Component | string. I'd love to solve it rather than ignoring it.Componentis a reserved keyword or I am destructuringComponentfromreactitself so I think it should be fine even if I rename it :)