Hacker News new | ask | show | jobs
by arp242 515 days ago
This is also one of those things that can be quite tricky to modify down the line when you need to add a new feature or whatnot. This problem is of course very artificial and it doesn't sound like the interview was particularly well done, but I can kind of see what they were trying to do with "keep code maintainable as it evolves". And even if you are a TS-wizard with a Ph.D. in typing: is it really worth all the cognitive overhead?
4 comments

I thought domain modelling through types is considered standard in functional programming?

(see for example Scott Wlaschin)

Honestly? It REALLY is.

This kind of typing in TS is used mostly for getting dynamically typed Javascript codebases under control.

I did this once for a state management library that was considered "impossible to add types to" by the authors themselves, and thanks to this I found several bugs in the library itself, and in our own codebase, due to subtle incorrect usage.

Just the fact that we got autocompletion across the whole app was worth the effort. Even the engineer that was against it ended up praising it.

I'm not the kind of person to say this but: maybe some things are not for everyone. Some people just have different interests and skills. Complicated things aren't less worth just because someone in the team can't understand them.

The FizzBuzz story did go down a rabbit hole, but this sort of TS type extravagance in small doses can help with maintainability. E.g., I wanted to enforce that the keys in a config object couldn’t have consecutive uppercase letters, because they would be automatically translated to camel case when looked up as environment variables (so awsAPIKey would become AWS_A_P_I_KEY, ugh). No need for a lint rule or whatever, you can do that with TS types in a few lines!
> And even if you are a TS-wizard with a Ph.D. in typing: is it really worth all the cognitive overhead?

Yes, but only on the weekends :)