Re:Don't DRY Your Code Prematurely
by cloverich on Thursday May 30, 2024 @05:30PM
(#40528931)
One area I find DRY particularly annoying is when people overly abstract Typescript types. Instead of a plain interface with a few properties, you end up with a bunch of mushed together props like { thing: boolean } & Pick<MyOtherObj, 'bar' | 'baz'} & Omit<BaseObj, 'stuff'> instead of a few duplicated but easily readable interfaces:
Re:Don't DRY Your Code Prematurely
by jddj on Thursday May 30, 2024 @06:28PM
(#40529455)
Am I crazy for almost exclusively just using type and sum types and no generics or interfaces and somehow being able to express everything I need to express?
Re:Don't DRY Your Code Prematurely
by Aeolun on Thursday May 30, 2024 @06:45PM
(#40529586)
Hmm, you can do pretty nice things with generics to make some things impossible (or at least fail on compile), but I agree it’s hardly readable. In some cases you need that though.
interface MyProps { thing: boolean; bar: string; baz: string; stuff: string; }