I guess I'm still a C++ programmer at heart. I was just spinning up a very simple helper class to clean up some debug UI:
const MaybeIfValue: React.FC<{text: string, value: any}> = ({text, value}) => {
if (value === undefined) {
return null;
}
if (value === null) {
return null;
}
return (
<div>
<span>{text}</span>{value}<br/>
</div>
);
}
...and I was thinking, I really don't want any
value here. Not that it's going to matter here in practice, this is a one off helper function. But plenty of times in development over the years I've accidentally tried to render something complex. I'm still only moderately experienced with Typescript, so I don't quite know the right term for it, but what I'm wondering about, is how do I static_assert
that the compile-time typeof value is renderable? I'd call it a type trait in C++. What's the term in typescript? Matching?