skip ReadonlyMap and ReadonlySet types when not available #653
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.
This should fix #624 .
Instead of my initial idea of providing interfaces with the same shape as
ReadonlyMap
,ReadonlySet
,WeakMap
andWeakSet
(which would also have worked, but probably required a lot more duplicate code), this is now following a different approach:It checks if the types are
any
(which they would fall back to if they were not present) or a keyless interface (which at leastReadonlyMap
andReadonlySet
would be if thenode
types are installed), in which case they fall back tovoid
, which does not trigger the conditional.The check for
any
is done bytrue | false extends (T extends never ? true : false)
- every other type will either betrue
orfalse
, but sinceany
takes both paths, it becomestrue | false
.The check for the empty interface is done by
keyof T extends never
- everything except the empty interface has some keys, including primitives likestring
andnumber
(which will have the keys of their prototype).