Open vaibhavrajsingh2001 opened 5 months ago
Hey @pjmolina, came across this issue while I was trying to iterate over the properties
field of a SchemaObject
.
Would appreciate a review here 🙏.
I have contradicting feelings here:
To be honest, not sure if it is makes worthy. And if we are breaking uses cases for anyone else.
Using mapped types like
{ [propertyName: string]: SchemaObject | ReferenceObject }
doesn't ensure the key to be of typestring
. Instead, TypeScript interprets the key asstring | number
.This behaviour can be verified in the following playground
Due to this issue, if you iterate over the properties of a schema, TypeScript can't be sure that the key is of type
string
. Instead the key will be interpreted as of typestring | number
.Using a
Record
allows to strictly type the key to only be of typestring
, which can be verified hereIt's a known TypeScript issue https://github.com/microsoft/TypeScript/issues/48269