gristlabs/ts-interface-checker

Option to not allow empty strings

ibc opened this issue · 1 comments

ibc commented

Currently if an interface has foo: string;, an empty string (foo: "") becomes valid. I think that in 99% of cases, when an interface declares a mandatory string it's desired that it's not an empty string.

Perhaps this lib could add an options to require this?

I could see it being useful. You could add a type like NonEmptyString to your type suite:

createCheckers({
  ...typeSuite,
  NonEmptyString: new BasicType((v) => (v && typeof v === "string"), "is not a non-empty string"),
});

If it seems useful enough, this could also be added to basicTypes in lib/types.