3 ms·
On the flip side, if you can't find a close enough type definition with reasonable effort, it's often a sign that you're about to enter gibberish type territory
by Etheryte 1y ago
On the flip side, if you can't find a close enough type definition with reasonable effort, it's often a sign that you're about to enter gibberish type territory and it might be time to reconsider. Even if a type does exist in the end, it might be unparseable to every human on your team, future you included.
- Tade0 1y agoThis. I regret every use of `infer`, save for one instance in which it actually helped, but it was a side project anyway.
- insin 1y agoBeing stuck in the typing rabbit hole for more than X minutes is a free pass to // @ts-ignore that one problematic line in the middle (particularly when it's "these objects I'm merging add up to the expected thing, but it would take a mountain of spaghetti to make TypeScript understand this")
- Jenk 1y ago.. or just type MergedType = TypeA & TypeB
- sieabahlpark 1y ago[dead]
- Etheryte 1y agoThis infamously does not work for factories though, or has that changed since I last checked? Typescript is great, but there are a number of places where it isn't quite there.
- no_wizard 1y agoThis would get bounced where I work. No way we would allow this. 9.9/10 cases there is a design flaw happening here, I and others I work with have found this to be true. We have zero // @ts-ignore statements in a very large code base that dozens of developers work with every day. Using interface extensions properly helps tremendously here
- johnfn 1y agoThis is too severe. There are reasons to need // @ts-ignore. Probably the biggest one in my experience is the inability to type functions with conditional return statements[1]. Probably a good rule of thumb is that you get to use a ts-ignore if you can link it back to an open issue on the TS repo :) [1]: https://github.com/microsoft/TypeScript/issues/33912 https://github.com/microsoft/TypeScript/issues/33912
- prairieroadent 1y ago[dead]
- no_wizard 1y agoI have yet to run into someone who couldn't actually resolve the issue by approaching the problem in a different way. Its why I said 9.9 not 10/10, as this would be a case where would have to comment liberally, but yeah, file an issue with the repository and go from there. That said, I haven't run into this in my many years of working with TypeScript except once.
- johnfn 1y agoC'mon man. Just one more type, and then the whole repo will be sound. Just one more type. Just one tiny little `infer`. What could possibly go wrong?