-
Notifications
You must be signed in to change notification settings - Fork 12.5k
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
Support Intellisense for string/number literals in a widened union #33471
Comments
keep it broken so people stop writing types like that |
There 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. |
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 |
type 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 |
👋 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 ❌ Failed: -
Historical Information
|
( I've updated the comment which should make the output above make more sens e on the next run ) |
I was surprised to find a PR to the DOM lib types microsoft/TypeScript-DOM-lib-generator#1467 actually using a side-effect in union handling to get this feature! // @errors: 1002
type T = "off" | "on" | "name" | (string & {});
declare function t(t: T){}
t("any string")
t("on") (edit: removed the twoslash repro because it doesn't take completions into account ) |
👋 Hi, I'm the Repro bot. I can help narrow down and track compiler bugs across releases! This comment reflects the current state of this repro running against the nightly TypeScript. ❌ Failed: -
Historical Information
|
Search tags: open ended string union literal auto complete See also #26277 |
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:
The text was updated successfully, but these errors were encountered: