-
Notifications
You must be signed in to change notification settings - Fork 216
Open
Description
Hi,
I'd like to know if this is a known issue and whether there's a chance that ts-json-schema-generator addresses such cases. This is currently preventing me from migrating away from typescript-json-schema which has its own limitations.
NB: the only change between the Good and the Bad case below is the position of RemoveNulls, which should be functionnally equivalent.
Good 👍
Input:
type RemoveNulls<T extends object> = { [P in keyof T]: Exclude<T[P], null> };
type IdType = number;
type XBaseType = {
str: IdType | null;
};
type XNullableType = RemoveNulls<XBaseType> & {
bar?: string;
};
export type XType = XNullableType;Output:
{
"$schema": "http://json-schema.org/draft-07/schema#",
"type": "object",
"properties": {
"bar": {
"type": "string"
},
"str": {
"type": "number"
}
},
"required": [
"str"
],
"definitions": {}
}Bad 👎🏻
Input:
type RemoveNulls<T extends object> = { [P in keyof T]: Exclude<T[P], null> };
type IdType = number;
type XBaseType = {
str: IdType | null;
};
type XNullableType = XBaseType & {
bar?: string;
};
export type XType = RemoveNulls<XNullableType>;Output: (str is mangled!)
{
"$schema": "http://json-schema.org/draft-07/schema#",
"type": "object",
"properties": {
"str": {
"not": {}
},
"bar": {
"type": "string"
}
},
"required": [
"str"
],
"definitions": {}
}Keep up the great work,
Cyril
Metadata
Metadata
Assignees
Labels
No labels