Closed amiran-gorgazjan closed 1 year ago
Nevermind, this bug report is incorrect - it turns out actually TypeScript behaves like this and the generated type by this library itself is correct. Closing.
Hello @amiran-gorgazjan ! Yes I don't think it's an issue with FromSchema
.
You can use the noUncheckedIndexedAccess ts option: https://www.typescriptlang.org/tsconfig#noUncheckedIndexedAccess
Expected behavior
Given a schema:
It will pass validation against:
See also: https://www.jsonschemavalidator.net/s/Plkz5SSq
Therefore, the type of the above array should be
({ id: number } | undefined)[]
And we would expect the following to show a TS error:
Actual behavior
json-schema-to-ts
currently results in the type{ id: number }[]
and therefore the above reference error is not caught and will fail at runtime.The same issue is already present in the
README.md
first example:hobbies?: string[];
should actually behobbies?: (string | undefined)[];