Repository navigation
Add union type - #766
Open
bvisness wants to merge 2 commits into
Open
Add union type#766bvisness wants to merge 2 commits into
bvisness wants to merge 2 commits into
Conversation
Just a bunch of drive-by updates made as part of union/overload work.
Collaborator
Author
|
I have updated this PR to only contain unions, and have moved overloads to #774. |
Draft
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Adds support for
union(a variant ofvariant). The design of unions is mostly unchanged from what @eqrion originally proposed (maybe modulo some of the mapping from types to distinguishable kinds).Resolves #724.
One thing I wanted to discuss is the distinguishability rules (which may eventually be reused for overloads). It's really hard to find a set of "distinguishable kinds" for each type that will actually avoid conflicts in various languages without being totally useless. The danger, in my opinion, is "kind creep", where you keep adding more distinguishable kinds to each component type, e.g. adding the
listkind to the componentmaptype because maps are frequently iterable in source languages. This reduces ambiguity for bindings, but makes unions much less useful.In my opinion the right way to handle this is to be stricter about types when in a "distinguishable context". You can see this reflected in the updated JS API. A plain old
list<string>parameter will accept any JS iterable (in TypeScript terms,Iterable<string>), whereas aunion{ list<string>, ... }parameter requires a JS array (Array<string>). In other words, the runtime would literally runArray.isArrayto decide if the value is "list-like", rather than checking forSymbol.iterator. This should only be a modest complexity cost for devs and one that TypeScript will catch right away. And importantly it ensures that union parameters should round-trip nicely; e.g. aunion{ list, map }will flow out to JS as anArrayorMapand back to components as alistormap, without any awkward crossover.