Non strict string literal types

Hey everyone. I want to keep intellisense suggestions when defining something like this:
type SuggestedStrings = "cat" | "dog" | string;
type SuggestedStrings = "cat" | "dog" | string;
I want to be able to accept any other string but have suggestions when defining a variable. I am not sure what would be the right keyword to search for in this situation.
7 Replies
Fursum
FursumOP2y ago
Using uppercase String seems to be working, though I am not sure if it is completely safe to do so in my situation with React stuff. It is only defined as a type, so I am assuming it wouldn't do some coersion in the background prayge
type SuggestedStrings = "cat" | "dog" | String;
type SuggestedStrings = "cat" | "dog" | String;
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
Fursum
FursumOP2y ago
the utility type is a cool idea, thanks!
Fursum
FursumOP2y ago
string literal union autocomplete
yeah... https://github.com/microsoft/TypeScript/issues/29729
GitHub
Literal String Union Autocomplete · Issue #29729 · microsoft/TypeSc...
Autocomplete works for literal string unions, but adding a union of string negates autocomplete entirely. This has been brought up before but I believe there is enough value in this feature to be r...
bedesqui
bedesqui2y ago
It's your lucky day, THE typescript wizard has a video explaining how to do it and why it works this way
bedesqui
bedesqui2y ago
all hail the wizard 🧙‍♂️
Want results from more Discord servers?
Add your server