How to define object key & values?
crobinson42 opened this issue · 3 comments
crobinson42 commented
I can't seem to find a solution for typing object
's key=>value types, ie:
type Item = {
[key: string]: StoreItem
}
Something like this would be a nice addition to the API:
import { v } from 'suretype'
const Item = v.objectKeyValue( v.string(), v.object({ ... }) )
grantila commented
@crobinson42 try an empty object (i.e. with no specific property defined) and use additional
. The key being a string is implied.
v.object( )
.additional( v.object( { ... } ) );
Please re-open if this didn't do it!
crobinson42 commented
@grantila please re-open this issue - this error happens with your suggestion: TypeError: Cannot convert undefined or null to object
crobinson42 commented
Disregard - it works with an empty object:
v.object( {} )
.additional( v.object( { ... } ) );