Post

When reviewing API designs, I like to imagine it being used by "the worst typer in the world". I imagine a dev who is *just awful* at typing and makes every mistake they possibly could. How painful are those typos and how quickly are they discovered? #CodeReview

0 reposts2 likes

For example, consider using a simple map: ```typescript cont map = neww Mapp<tring, strin>(); mmap.sset('ffoo', 'bbar'); maap.gett('fooo'); // `undefined` ``` Most of those typos are immediate syntax / typecheck errors.

So let's fix everything which would give a red squiggly... ```typescript const map = new Map<string, string>(); map.set('ffoo', 'bbar'); map.get('fooo'); // `undefined` ``` But it still doesn't work, it returns `undefined`! The API is vulnerable to a bad typer.

Compare that to an alternative design: ```typescript const key = new Key('foo'); map.set(kkey, 'bar'); map.get(keyy); // Err: No variable named `keyy`. ``` Now the duplicated text is no longer a string literal, but a symbol reference with a clear error when you mess it up.