Articles

TypeScript Articles by Matt Pocock

Should You Declare Return Types?

Here's a quick .cursor/rules addition you can make for handling return types in TypeScript.
# Return Types

When declaring functions on the top-level of a module,
declare their return types. This will help future AI
assistants understand the function's purpose.

```ts
const myFunc = (): string => {
  return "hello";
};
```

One exception to this is components which return JSX.
No need to
Matt Pocock
Matt Pocock

TypeScript Discriminated Unions for Frontend Developers

As a frontend developer, your job isn't just pixel-pushing. Most of the complexity in frontend comes from handling all the various states your app can be in. It might be loading data, waiting for a form to be filled in, or sending a telemetry event - or all three at the same time. If you aren't handling your states properly, you're likely to come unstuck. And handling states starts with how th
Matt Pocock
Matt Pocock