Allow empty string but fail on undefined
See original GitHub issueAccording to README, it should be possible to require empty string:
To allow empty strings but fail on undefined values use:
string().required().min(0)
However, this does not seem to work:
const yup = require("yup")
const okString = 'foo';
const shouldBeOkString = '';
let nokString;
const schema = yup.string().required().min(0);
console.log(await schema.isValid(okString)); // true
console.log(await schema.isValid(shouldBeOkString)); // false <--
console.log(await schema.isValid(nokString)); // false
Same with yup.array().required().min(0)
won’t allow []
.
Am I missing something?
Issue Analytics
- State:
- Created 6 years ago
- Comments:9 (7 by maintainers)
Top Results From Across the Web
How do I check for an empty/undefined/null string in JavaScript?
It will check the length, returning undefined in case of a nullish value, without throwing an error. In the case of an empty...
Read more >Null and undefined (Reference) - Prisma
How Prisma Client handles null and undefined, including a GraphQL use case. ... authorEmail is null , the query will fail - email...
Read more >Documentation - TypeScript 2.0
Null - and undefined-aware types. TypeScript has two special types, Null and Undefined, that have the values null and undefined respectively.
Read more >Checking for an Empty, Null, or Undefined String - YouTube
In this quick take, learn all about how you can to see whether your strings contain a valid value or not.
Read more >JavaScript Check Empty String – Checking Null or Empty in JS
How to Check for Null in JavaScript. So far, we've seen how to check if a string is empty using the length and...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I don’t see how to do the old
case anymore. Do I have to now provide a custom yup method? I made a SO question asking for help https://stackoverflow.com/questions/63943689/how-to-get-yup-string-to-require-string-of-any-length-including-0
Thanks!
In deed,
string().required().min(0)
fail miserably for empty strings.