No unknown keys
See original GitHub issueThis feature causes yup to throw an error on validation if there’s a property on the object that doesn’t match the schema. Similar to yup.object().noUnknown()
Split off from #14.
Issue Analytics
- State:
- Created 4 years ago
- Comments:6 (4 by maintainers)
Top Results From Across the Web
typescript type for object with unknown keys, but only numeric ...
I want the typescript compiler to know that for all present keys, the value is numeric. I tried things like type numObj =...
Read more >TypeScript | Known and Unknown Keys - John Darryl Pelingo
There are cases where we have known and unknown keys in an object. Having at least the known keys will help with TypeScript...
Read more >TypeScript | Objects with Unknown Keys and Known Values
Learn how to define object types with unknown keys and known values using TypeScript by explaining with easy code examples.
Read more >Unknown Keys in Configuration profiles after 10.31 update
Solved: After our server was updated to 10.31 the unknown keys feature is presenting itself in a number of profiles. At first all...
Read more >Managing objects with unknown structures in TypeScript using ...
No index signature with a parameter of type 'string' was found on type '{}'. ... we define the type of keys and the...
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
@christophemarois I’ve been thinking about this a fair bit.
I think I’ll introduce a
.mask()
method on object schemas that lets you pass in a properly typed instance and get back a new object with some subset of the properties. Like so:In your situation I’d recommend creating a proper recursive type for the sake of representational accuracy:
.mask
isn’t actually implemented yet, I was just toying with the idea. Would this work for your use cases? I’ll leave this issue open in the meantime.I don’t know if you’d consider also adding yup’s
stripUnknown
option, which is related to thenoUnknown()
behavior, but is not treated as an error.This would be a really useful feature for my particular use-case: I have React components that take as a prop an object with circular dependencies (think ActiveRecord). I currently use yup with to do both prob validation and “picking” properties, so I end up with an object that is serializable, that I can send over HTTP, and that only contains the property I need.
I have a working workflow with yup, but the lack of optional types and correct type inference is problematic.
Extremely dumb yup example to illustrate my point: