Pages

Tuesday, May 29, 2018

What's Component anyway? (TypeScript React)

What's Component<any, any> in Typescripted React? Props and state. I mean, you knew that, but here's some confirmation. Took me a while for my desire for confirmation and ability to google successfully to match up.

From github.io:

Sometimes you’ll see definitions like class MyComponent extends React.Component<{}, {}>. This means that this component doesn’t use props or state—they must be empty. class MyComponent extends React.Component<any, any> says that you can pass anything for props and state and it will do no type checking.

What a weird mishmash of C# and JavaScript this TypeScript is. I mean, I like it, but it feels like an incomplete language that allows shortcuts borrowed directly from two different languages. I'm not saying I dislike it, but TypeScript is a strange pastiche of programming paradigms.