3 ms·
Function return type inference is funny but I don't think it's that great of a feature. It makes it harder for a library's consumer to know how to properly use
by thrance 1y ago
Function return type inference is funny but I don't think it's that great of a feature. It makes it harder for a library's consumer to know how to properly use a function, and it also makes it harder for the maintainer to not break backwards compatibility inadvertently. Anyway, I'm all for experimenting.
- beariish 1y agoThere's nothing stopping a library author from explicitly annotating return types wherever a stable interface is important, the idea is more for smaller functions or callbacks to make use of this. Perhaps I'll make the examples clearer to reflect the intention.
- flakes 1y agoPerhaps it makes more sense to say that exported function interfaces be explicit. That forces you to document the api and more carefully consider changes.
- jitl 1y agoIt’s great in TypeScript. In TypeScript your source can have inferred types returned, and then use a build step to produce resolved typings files (.d.ts) for distribution that have the fully specified type.
- thrance 1y agoAh, true, now that you mention it. I feel like it's the best of both worlds, you get type inference and it gets documented automatically.