Repository navigation
Support Intellisense for string/number literals in a widened union #33471
Description
Activity
RyanCavanaugh commented
on Sep 17, 2019 MemberMore actionskeep it broken so people stop writing types like that
Reacted by Jordi Oliveras Rovira, Jason Kwok, Chayim Refael Friedman, Danilo Fuchs and 19 moreReacted by Jason KwokThere are situations when implementing 3rd party APIS where you know the options that there are right now, but future versions will absolutely add new options.
If you use a closed union type, you get auto completion but errors on every new option that is added. If you use string, you lose auto completion.
How to solve this dilemma?- addedExperience EnhancementNoncontroversial enhancementsNoncontroversial enhancementsSuggestionAn idea for TypeScriptAn idea for TypeScript
on Sep 17, 2019 I say this as someone who extolls the virtues of self-documenting code constantly...
IMO, this is conflating purely documentary concerns with typing concerns. In reality, the type is just
stringand we shouldn't pretend otherwise. I understand the value of having an automatic list of suggestions, but that feels more like the domain of documentation-level scaffolding such as JSDoc comments, rather than the type system proper.Reacted by Stephen Haneyjack-williams commented
on Sep 18, 2019 CollaboratorMore actionstype ErrorStatus = (('not_found' | 'failed' | 'parse_error') & tag "suggestions") | string;
Whoa, hold on. Will this actually be a use case of tag types? 😳
crosslinking to #29729
- addedRepro RequestedIndicates that we'd like a compiler backed repro for this issue: https://aka.ms/ts-reprosIndicates that we'd like a compiler backed repro for this issue: https://aka.ms/ts-repros
on Jul 20, 2020 - addedHas ReproThis issue has compiler-backed repros: https://aka.ms/ts-reprosThis issue has compiler-backed repros: https://aka.ms/ts-reprosand removedRepro RequestedIndicates that we'd like a compiler backed repro for this issue: https://aka.ms/ts-reprosIndicates that we'd like a compiler backed repro for this issue: https://aka.ms/ts-repros
on Jul 20, 2020 - changed the title
[-]Support Intellisense for string/number literals in a widened array[/-][+]Support Intellisense for string/number literals in a widened union[/+]on Mar 3, 2022 typescript-bot commented
on Apr 13, 2022 ContributorMore actions👋 Hi, I'm the Repro bot. I can help narrow down and track compiler bugs across releases! This comment reflects the current state of the repro in the issue body running against the nightly TypeScript.
Issue body code block by Orta Therox (@orta)
‼️ Exception: Error - error TS5107: Option 'moduleResolution=node10' is deprecated and will stop functioning in TypeScript 7.0. Specify compilerOption '"ignoreDeprecations": "6.0"' to silence this error. Visit https://aka.ms/ts6 for migration information.Error: error TS5107: Option 'moduleResolution=node10' is deprecated and will stop functioning in TypeScript 7.0. Specify compilerOption '"ignoreDeprecations": "6.0"' to silence this error. Visit https://aka.ms/ts6 for migration information. at Object.createVirtualTypeScriptEnvironment (/home/runner/work/_actions/microsoft/TypeScript-Twoslash-Repro-Action/master/dist/index.js:8128:11) at twoslasher (/home/runner/work/_actions/microsoft/TypeScript-Twoslash-Repro-Action/master/dist/index.js:7618:17) at /home/runner/work/_actions/microsoft/TypeScript-Twoslash-Repro-Action/master/dist/index.js:439:44 at runTwoslashRequests (/home/runner/work/_actions/microsoft/TypeScript-Twoslash-Repro-Action/master/dist/index.js:406:56) at run (/home/runner/work/_actions/microsoft/TypeScript-Twoslash-Repro-Action/master/dist/index.js:20096:75) at process.processTicksAndRejections (node:internal/process/task_queues:95:5)Historical Information
Version Reproduction Outputs Time 4.2.2, 4.3.2, 4.4.2, 4.5.2, 4.6.2 ⚠️ Assertions:⚠️ Way slower( I've updated the comment which should make the output above make more sens e on the next run )
18 remaining items
- added a commit that references this issue
on Jan 27, 2026 - added a commit that references this issue
on Jan 27, 2026 - added a commit that references this issue
on Jan 28, 2026 - added a commit that references this issue
on Jan 30, 2026 - added a commit that references this issue
on Jan 31, 2026 - added a commit that references this issue
on Feb 1, 2026 - added a commit that references this issue
on Feb 2, 2026 - added a commit that references this issue
on Feb 3, 2026 - added a commit that references this issue
on Feb 10, 2026 - added a commit that references this issue
on Feb 11, 2026 - added a commit that references this issue
on Feb 11, 2026 - added a commit that references this issue
on Feb 14, 2026 - added a commit that references this issue
on Feb 16, 2026 - added a commit that references this issue
on Feb 19, 2026 - added a commit that references this issue
on Mar 3, 2026
Search Terms
autocomplete union wide
Suggestion
In both #28743 and #28743 they were correctly closed for being correctly widened to a string.
Use Cases
I'd like to pitch that this is useful only from the IDE experience, and that's purely where the value comes in from. The widening to a string makes sense, however allowing this lets you declare an API where you would like to allow any input, but there are preferred options.
Examples
Would offer "not_found", "failed", "parse_error" in the completion list.
Checklist
My suggestion meets these guidelines: