DefinitelyTyped / DefinitelyTyped/DefinitelyTyped
[yup] InferType should default to nonRequired()
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 51.4k
- Forks
- 30.4k
- Avg merge
- 3d 21h
- Merged PRs (30d)
- 108
Description
Issue
When creating a schema with Yup, you don't get validation errors on validate if a property is missing; it's non-required by default.
When using InferType<>, it marks all properties as required by default unless explicitly noted as notRequired(), which leads to TS errors in vscode
Sample
import {object, string, InferType} from 'yup'
const schema = object({
requiredString: string().required(),
notRequiredString: string()
})
// Some method that takes schema json as an argument
const method = (json: InferType<typeof schema>) => {}
// Error: Property 'notRequiredString' is missing in type '{ requiredString: string; }' but required in type (...)
method({
requiredString: "done"
})
Expected
The above should show no error since notRequiredString isn't marked as required
- Authors: @dhardtke @vtserman @MoretonBayRC @sseppola @YashdalfTheGray
@vincentjames501 @robertbullen @sat0yu @deskoh @mauricedb @kalley
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by locating the Yup TypeScript definitions for InferType and the object schema shown in the issue. Check how an unmarked string field is represented compared with requiredString, then add coverage demonstrating that the inferred notRequiredString property may be omitted while requiredString remains required.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- developer-experience
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 30/100