With the awesome work @andy-haynes did to refactor how props can be passed more naturally (without nesting them in a props object), I realized we could start using a more natural typed component syntax that provides better type safety and ergonomics overall.
Here's an example of the syntax that I'm describing:
import s from './styles.module.css';
type Props = {
message?: string;
};
const TypedComponentChild: BWEComponent<Props> = ({ message = 'default message' }) => {
return (
<div className={s.wrapper}>
<p>This is the child message: {message}</p>
</div>
);
}
export default TypedComponentChild;
Instead of having to do a cast explicitly for the export - which could be easy to forget or confusing since it's not a very common pattern (casting combined with an export statement):
export default RocChildTest as BWEComponent<Props>;
However, I ran into an interesting bug that I documented with a Loom: https://www.loom.com/share/398d0a396f1c43b8af203c14ec932a1b
With the awesome work @andy-haynes did to refactor how props can be passed more naturally (without nesting them in a
propsobject), I realized we could start using a more natural typed component syntax that provides better type safety and ergonomics overall.Here's an example of the syntax that I'm describing:
Instead of having to do a cast explicitly for the export - which could be easy to forget or confusing since it's not a very common pattern (casting combined with an export statement):
However, I ran into an interesting bug that I documented with a Loom: https://www.loom.com/share/398d0a396f1c43b8af203c14ec932a1b