ts-json-schema-generator
ts-json-schema-generator copied to clipboard
Support for `infer` in template literals, intrinsic types and more
Closes https://github.com/vega/ts-json-schema-generator/issues/1355
Adding full type inference for template literals were quite a lot more work than first anticipated, particularly because TemplateLiteralNodeParser
would narrow the type to a LiteralType
, StringType
or UnionType
before sent to isAssignableTo
in ConditionalNodeParser
. My proposed solution is to add a check within TemplateLiteralNodeParser
to see if the node exists within an extends clause of a conditional, in which case we create a new TemplateLiteralType
where we retain the original information stored in the template literal, which allows us to segment through the parts and verify if the source is assignable.
Additionally, I've done the same for IntrinsicNodeParser
, which had the same limitations, where both StringType
and InferType
as an argument in a condiitonal type would fail.
I've added extensive test cases for both.