Closed hinkik closed 2 years ago
Adds a KeyOf type that can be used like this
myObject = { foo: "bar", 4: "foobar", } const keyOfObjectSchema = ft.KeyOf("nameOfMyObjectKeys", myObject)
Potential issue: Object.Keys(...) returns string[] and thus other types than string keys become degenerated which means that
string[]
keyOfObjectSchema.parse("4") // "4"
even though "4" is not a member of keyof typeof myObject. Furthermore, other types that are not number will always fail the parsing.
keyof typeof myObject
Since all js object fields becomes strings, perhaps one needs to enforce the keys to be strings in the first place?
KeyOf(SomeObject)
keyof typeof SomeObject
Edit changelog
Adds a KeyOf type that can be used like this
Potential issue: Object.Keys(...) returns
string[]
and thus other types than string keys become degenerated which means thateven though "4" is not a member of
keyof typeof myObject
. Furthermore, other types that are not number will always fail the parsing.Since all js object fields becomes strings, perhaps one needs to enforce the keys to be strings in the first place?