TypeScript Wiki
Same gray. Which if returned it?
buttonColor checks the button’s variant from top to bottom and returns a color at the first match. Switch from ghost to secondary: the button stays gray, but a different line returns it.
From my November 27 notebook
I first compared variant with "red". The input is "danger"; "red" is the output. Each pair of braces encloses one if, like a frame in Figma. If the first three checks fail, only secondary is left.
Why does TypeScript flag string when all four buttons work?
The return annotation promises a string on every call. With strictNullChecks on, TypeScript cannot prove that this sequence of if statements always returns before the end (TS2366). A final return "gray" would also catch any newly added variant and quietly color it gray.