Skip to content

Conversation

@ascorbic
Copy link
Contributor

Changes

Use the | (string & {}) trick to ensure that key autocomplete always works

Testing

Docs

@changeset-bot
Copy link

changeset-bot bot commented Apr 15, 2025

🦋 Changeset detected

Latest commit: 4b604f3

The changes in this PR will be included in the next version bump.

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@github-actions github-actions bot added the pkg: astro Related to the core `astro` package (scope) label Apr 15, 2025
Copy link
Member

@florian-lefebvre florian-lefebvre left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Gotta love this trick!

@codspeed-hq
Copy link

codspeed-hq bot commented Apr 15, 2025

CodSpeed Performance Report

Merging #13622 will not alter performance

Comparing key-autocomp (4b604f3) with main (406501a)

Summary

✅ 6 untouched benchmarks

Copy link
Member

@ematipico ematipico left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Out of curiosity, what does this trick do?

@ascorbic
Copy link
Contributor Author

@ematipico It lets you type something to accept any string, but also get autocomplete from a string union. If type something as SomeStringUnion | string then it resolves to just string, so you get no autocomplete, but due to a TypeScript quirk, typing it as SomeStringUnion | (string & {}) means it accepts any string but still gives autocomplete for the union values. This is so useful the TS team has decided to not fix the "bug".

@ascorbic ascorbic merged commit a70d32a into main Apr 15, 2025
16 checks passed
@ascorbic ascorbic deleted the key-autocomp branch April 15, 2025 14:14
@astrobot-houston astrobot-houston mentioned this pull request Apr 15, 2025
openscript pushed a commit to openscript/astro that referenced this pull request Sep 12, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pkg: astro Related to the core `astro` package (scope)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants