Skip to content

Feature request: Builtin for case-insensitive literals and unions #6743

@motiz88

Description

@motiz88

Motivated by the desire to model case-insensitive DOM attribute values, the idea is to create a builtin, perhaps called $CaseInsensitive, that would make the following possible:

const valid: $CaseInsensitive<"foo" | "bar"> = "Foo"; // OK
const invalid: $CaseInsensitive<"foo" | "bar"> = "baz"; // Error

I imagine this would also come with intrinsic understanding of constructs such as

let x: $CaseInsensitive<"foo" | "bar"> = /* ... */;

if (x.toLowerCase() === "foo") {
// ...
}

switch (x.toLowerCase()) {
case "foo":
// ...
case "bar":
// ...
}

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions