Return a Value or Nothing
Write the code, see it run, pass the checks.
The problem
- easy
- Code
Export a type User with an id (a number) and a name (a string), and write findUser(users, id), which returns the user with that id, or undefined when there isn't one. Type the result as User | undefined, so callers have to check before reading the name.
Your code must pass
- Finds the user with the id
- Returns undefined when there isn't one
- Has no type errors
- Returns a User or undefined
- Callers must check before reading the name