When migrating some code to TypeScript, I ran into a few little hurdles I want to share with you. In EpicReact.dev workshops, when I’m teaching how to make HTTP requests, I use the GraphQL Pokemon API. Here’s how we make ...

I made a useDarkMode hook that looks like this: type DarkModeState = 'dark' | 'light' type SetDarkModeState = React.Dispatch<React.SetStateAction<DarkModeState>> function useDarkMode() { const preferDarkQuery = '(prefers-color-scheme: dark)' const [mode, setMode] = React.useState<DarkModeState>(() => { const lsVal = window.localStorage.getItem('colorMode') if (lsVal) ...

Allow me to quickly answer to the “normal” use case of “How to define function overload types with TypeScript” with an example: I want a function that accepts a callback or returns a promise if none is provided: const logResult ...

In JavaScript itself, there are lots of ways to write functions. Add TypeScript to the mix and all of a sudden it’s a lot to think about. So with the help of some friends, I’ve put together this list of ...

When you want to display a list of items to a user, I’m afraid .join(', ') just won’t cut it: console.log(['apple'].join(', ')) // apple // looks good console.log(['apple', 'grape'].join(', ')) // apple, grape // nah, I want "apple and grape" ...