Loosen typed strings in Typescript 2025/12/31 Wed - 02:09 PM
You can have string unions that allows any type of string, but with actual autocompletion. You can do this with a loose string union:
type AutocompleteLoosenStatus = "active" | "inactive" | (string & {});If you do like "et cetera" | string you will lose autocomplete.
Why?
The union with string & {} widens acceptance without collapsing the union into
plain string.
LooseString
You can create your own loose string union:
type LooseString<T extends string> = T | (string & {});
type Status = LooseString<"idle" | "loading" | "success" | "error">;
const a: Status = "idle"; // autocomplete
const b: Status = "customValue"; // allowed