I would like to define a property on a TS class that will accept any string but not an empty string (''). Is there a way to do this?
Something like this:
class Foo {
id: string & Not<''>
}
const bar = new Foo
bar.id = '' // ts compile error
bar.id = 'whatever string you want' // ts compile allowed
or
type nonEmptyString = Exclude<string, ''>
const something1: nonEmptyString = '' // ts compile error
const something: nonEmptyString = 'f' // ts compile allowed
const something2: nonEmptyString = '1' // ts compile allowed
T extends '' ? never : Tor something) . But I'm reasonably certain that its not possible to have the last three lines of your code work like you expect them to.type nonEmptyString = Exclude<string, ''>