I need a type that is essentially "any string except for {reservedKeywords}". However, that is apparently either impossible or tricky and undwieldly.
I can settle for having to specify the string literals to use.
This is as close as I can get to what I want, using Exclude<T,K>:
type AnySet<set extends string> = set
let test1: Exclude<AnySet<"a" | "1">, "1">
test1 = "a" //passes correctly
test1 = "1" //fails correctly
let test2: Exclude<AnySet<string>, "1">
test2 = "a" //passes correctly
test2 = "1" //passes (counterintuitively :( )
Is there any way I can prohibit passing string directly?
Furthermore, is there a way to define a type is any collection of string literals but not specifically a string?
Here's what I mean:
type AnySet<set extends string> = set
let test1: Exclude<AnySet<"a" | "1">, "1">
test1 = "a" //passes correctly
test1 = "1" //fails correctly
let test2: Exclude<AnySet<string>, "1">
test2 = "a" //passes correctly
test2 = "1" //passes (counterintuitively)
type FiniteSet<set extends ???> = set
let test3: Exclude<FiniteSet<"a" | "1">, "1">
test3 = "a" //should work
test3 = "1" //should not work
let test4: FiniteSet<string> //should fail
let test5: FiniteSet<"a" | "b" | "c"> //should work