fix: refine the types more, to improve type extends behaviour #234
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
See also: #233 (i pulled the doc comment from here), #232, #231
The old types prevented
from working properly, as typescript borked where it fails to match
the arguments types with impossible-to-reach types.
The smallest change to achieve this fix is to change the
any[]
inArguments<...>
tonever
.to understand this change, understand that the reference to the
Arguments
type will never reach theany[]
case from within theEventListener
type mapping, sinceK
already must be akeyof T
once we're in the alternate(else, after the :) branch ofT extends string | symbol
, sinceEventNames
in this case will be specificallykeyof T
.Typescript just isn't smart enough to them since this situation runs in parallel (not actually parallelism, just like, conceptually) in the type checker, the invariant i've attempted to describe is coincidental; the causation doesn't flow from one to the other or vice versa.
And the
ArgumentMap
type will already handle theany[]
type for when the value in the object isn't a function or array.Hope you can understand this explanation well enough to merge this change! I've done my best, i could do better with a whiteboard.
Also, i don't like having the type name
Arguments
because it's too close (IMO) to the builtinIArguments
, so I felt it worthwhile to just remove that type, keep it smaller.