Suggestion: Explicit error messages in declaration files #14977
Labels
Awaiting More Feedback
This means we'd like to hear from more people who would be helped by this feature
Suggestion
An idea for TypeScript
It would be nice if type declaration files had a way to declare that an overload should never match and, if it does, to provide a helpful error message.
Context: I've been playing around with trying to write precise type declarations for Lodash's
chain
method._.chain(array).mapValues()
should be an error, but_.chain(dict).mapValues()
shouldn't.Here's the code I'm working with:
When this method is used correctly, it deduces the type perfectly. But when it's used incorrectly, e.g. on an array instead of a Record type, the error message is cryptic:
This feels vaguely like the morass of C++ template error messages! It would be nice if I could either:
mapValues
case. Something like:Dict extends Record<K, V>
to the declaration but I always either lose the precise key information (it becomesstring
rather than"a" | "b"
) or get mysterious inferrednever
types. (Broken inference between index typed object and Record #14930)TypeScript Version: 2.2.2
The text was updated successfully, but these errors were encountered: