Support discriminated unions
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 234
- Forks
- 92
- Avg merge
- 1d 3h
- Merged PRs (30d)
- 6
Description
Is your feature request related to a problem? Please describe.
If I iterate over all the blocks in a section, and each of those blocks have settings. Then if I discriminate on block.type, I should be able to have completion and hover support on block.settings.
{% for block in section.blocks %}
{% case block.type %}
{% when 'slide' %}
{{ block.settings.image }}
{% else %}
{% endcase }
{% if block.type == 'slide' %}
{{ block.settings.image }}
{% endif %}
{% endfor %}
{% schema %}
{
"name": "Slideshow",
"tag": "section",
"class": "slideshow",
"settings": [],
"blocks": [
{
"name": "Slide",
"type": "slide",
"settings": [
{
"type": "image_picker",
"id": "image",
"label": "Image"
}
]
}
]
}
{% endschema %}
Describe the solution you'd like
Do something a bit like typescript where you can discriminate on a union type and get a different one. This is kind of big because it means we might want to support union types as well. e.g. section.blocks being return_type [{ type: block_1 }, { type: block_2 }], etc.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the Liquid example and its schema blocks definition, then trace how section.blocks and block.type are represented for language features. Define the expected completion and hover behavior for block.settings in both case/when and if comparisons, including how multiple block variants are modeled. Done means the example narrows block.settings correctly for the discriminated type.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- developer-experience
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 30/100