json-schema-to-typescript
json-schema-to-typescript copied to clipboard
when schema is: {type: "object", default: "foo"}, the result type is: type Schema = string;
when "type" value is mismatch "defualt" value's type, the resutl is wrong.
This:
{ "type": "object", "default": "foo" }
Results in:
export type Schema = string;
While I would have expected:
export interface Schema { propertiesA: ... propertiesB: ... }
Without "default" or "default": {} it works fine.
What does it mean for default
to be a string, while the type
of the schema is an object?
JSON-Schemas accept the combination of the different types they may be; in your case, because default
is a string, that tells JSTT that the schema could be a string; JSTT then ignores type
(which is a bug). The right behavior is to accept either an object or a string. Would you prefer the following type?:
interface Schema1 {
[k: string]: unknown
}
export type Schema = Schema1 | string