TypeScript tip: Consider generating types


TypeScript tip: Consider generating types.

Example: I have a component library with 100 components. I want a union type that contains all the component names.

So, I:
1. Read the /components folder with Node.
2. Write each component's name to a union.

#typescript

In this case, I want a union type for each component.

Why?
✅I can safely reference a given component by name
✅I get autocomplete support

The union is generated each time I start the app. So, I don't have to manually maintain the type. 👍

View original on X