← Back to context

Comment by thrance

2 days 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.

There'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.

  • Perhaps it makes more sense to say that exported function interfaces be explicit. That forces you to document the api and more carefully consider changes.

It’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.

  • Ah, 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.