Language is not mentioned in a title, so my first thought was about TypeScript type wizardry. Turns out it's as simple as `Exclude<string, "">`.
https://www.typescriptlang.org/docs/handbook/utility-types.h...
Edit: nevermind, LLM fooled me.
https://www.typescriptlang.org/docs/handbook/utility-types.h...
Edit: nevermind, LLM fooled me.
https://www.typescriptlang.org/play/?#code/C4TwDgpgBAcg9gOwK...
declare const brand: unique symbol;
type NonEmptyString = string & { readonly [brand]: 'NonEmptyString' };
// the ONLY non-cast way to produce one
export function nonEmptyString(s: string): NonEmptyString | undefined {
return s.length > 0 ? (s as NonEmptyString) : undefined;
}
export type { NonEmptyString };You can do this trick for type-checking emptiness of string literals
https://www.typescriptlang.org/play/?jsx=0#code/C4TwDgpgBAsg...