Closed stalniy closed 3 years ago
any thoughts?
Good catch ! I'll have a look into it next week !
I can create a PR if you are ok with the fix, so the only thing you need to do is to release a new version :) Please, it's quite critical for me and I don't want to create hack-arounds
@stalniy It's merge and deployed in v1.6.1 👍 Thanks for your contribution !
Awesome! Thank you!
The issue
FromSchema
does not infer required properties whencompilerOptions.keyofStringsOnly = true
.The reason
I'm working on a project where ts compiler option
keyofStringsOnly
is set totrue
. This makeskeyof WHATEVER
to returnstring
type instead ofstring | number | symbol
. That's why when you check whethernumber
extendskeyof S["required"]
on this line, it return false.In general,
keyof
operator is not safe to test whether type is an array or tuple because even for objects and interfaces it returnsstring | number
.Also if you check the output type of
type indexesOfArray = keyof string[]
, you will see that ts returnsnumber
and names of all methods. Evenkeyof ReadonlyArray<string>
because it contains numeric indexes, length and all non mutating array methodsHow to fix
In order to fix the issue, you need to convert that and similar checks to check on
ReadonlyArray<string>
or on{ length: number }