Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for infer in template literals, intrinsic types and more #2053

Open
wants to merge 20 commits into
base: next
Choose a base branch
from

Conversation

flugg
Copy link
Contributor

@flugg flugg commented Aug 25, 2024

Closes #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.

Useful for extends types within conditional nodes
Added support for never types and template literal types for extends types
Useful for extends types within conditional nodes
Added support for returning intrinsic types for extends clauses. Also added support for Capitalize<string> expressions
…onditionals with mapped type

This type is the original type from our code which brought me onto this journey of adding support for more advanced inference in the first place. Thought it was good to have it here for reference in the future.
@domoritz
Copy link
Member

@arthurfiorette could you take a look at this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Type inference won't work with template literals
2 participants