Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

skip ReadonlyMap and ReadonlySet types when not available #653

Merged
merged 1 commit into from
Oct 20, 2020

Conversation

phryneas
Copy link
Contributor

@phryneas phryneas commented Aug 13, 2020

This should fix #624 .

Instead of my initial idea of providing interfaces with the same shape as ReadonlyMap, ReadonlySet, WeakMap and WeakSet (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 least ReadonlyMap and ReadonlySet would be if the node types are installed), in which case they fall back to void, which does not trigger the conditional.

The check for any is done by true | false extends (T extends never ? true : false) - every other type will either be true or false, but since any takes both paths, it becomes true | false.

The check for the empty interface is done by keyof T extends never - everything except the empty interface has some keys, including primitives like string and number (which will have the keys of their prototype).

@codesandbox-ci
Copy link

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

Latest deployment of this branch, based on commit e2e806f:

Sandbox Source
Immer sandbox Configuration

@mweststrate
Copy link
Collaborator

Thanks for the PR! Looks fine at first sight and clever trick :). However, if it turns out type checking becomes more expensive or there is other fallout, the changes might get referred.

@mweststrate mweststrate merged commit 12f4cf8 into immerjs:master Oct 20, 2020
@aleclarson
Copy link
Member

🎉 This PR is included in version 7.0.11 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

TypeScript: ReadonlyMap & ReadonlySet not available when targeting es5
3 participants