-
Notifications
You must be signed in to change notification settings - Fork 12.4k
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
Conditional types #21316
Merged
Merged
Conditional types #21316
Changes from 1 commit
Commits
Show all changes
44 commits
Select commit
Hold shift + click to select a range
57ca768
Initial implementation of conditional type operator
ahejlsberg 063eed1
Add type relationships and distribute over union types
ahejlsberg ec2bdfd
Add 'T extends U' type operator
ahejlsberg 43e195d
Clean up isGenericXXXType functions
ahejlsberg 61225cc
Introduce TypeFlags.Instatiable
ahejlsberg 9f74a7a
Rename TypeVariable to InstantiableType
ahejlsberg 20434fa
Inference for conditional and extends type operators
ahejlsberg ddc631c
Fix typo
ahejlsberg 000f121
Improve conditional type constraint checking
ahejlsberg 27b945b
Handle constraints for distributive conditional types
ahejlsberg f59e2e6
Accept new baselines
ahejlsberg 14590f1
Move JsxAttributes and MarkerType from TypeFlags to ObjectFlags
ahejlsberg 100e4f6
Accept new baselines
ahejlsberg c5fd2f1
Parse xxx? as JSDoc type when not followed by token that starts type
ahejlsberg 341c397
Accept new baselines
ahejlsberg 3f4911f
Fix linting error
ahejlsberg abc8110
Merge branch 'master' into conditionalTypes
ahejlsberg bb23bb2
Propagate both TypeFlags and ObjectFlags in getSpreadType
ahejlsberg c10a552
Eagerly evaluate S extends T when S is definitely or definitely not a…
ahejlsberg 53b1572
Revert to extends check being part of conditional type
ahejlsberg 5094f76
Remove 'T extends U' type constructor
ahejlsberg 925da86
Accept new baselines
ahejlsberg e8d1740
Introduce substitution types to use for constrained type parameters
ahejlsberg 15baf0e
Accept new baselines
ahejlsberg 9598acd
Properly handle 'any' and 'never' as conditional check type
ahejlsberg e96ec8c
Erase substitution types in type references and type alias instantiat…
ahejlsberg d52fa71
Optimize the sameMap function
ahejlsberg 4ec6fdd
Merge branch 'master' into conditionalTypes
ahejlsberg fd0dd6e
Separate code path for conditional type instantiation
ahejlsberg c360c24
Fix parsing
ahejlsberg 0e73240
Disallow conditional type following 'extends'
ahejlsberg 5204fd5
Add T is related to { [P in xxx]: T[P] } type relationship
ahejlsberg eb314d0
Add tests
ahejlsberg cdd50d4
Accept new baselines
ahejlsberg fc7d1c3
Revise comments
ahejlsberg f19959a
Cache substitution types and remove erasure that was too eager
ahejlsberg b869290
Remove unnecessary caching of substitution types
ahejlsberg 4c7ec3c
Shared code path for getConditionalType and instantiateConditionalType
ahejlsberg b42c6b1
Only conditional types that check naked type parameter distribute ove…
ahejlsberg 8e337b5
Fix bug in resolveMappedTypeMembers
ahejlsberg 4f2b5f3
Merge branch 'master' into conditionalTypes
ahejlsberg f990e4e
Merge branch 'master' into conditionalTypes
ahejlsberg 01516c8
Update to use TypeFlags.Instantiable in instantiateSymbol
ahejlsberg d4dc67a
Merge branch 'master' into conditionalTypes
ahejlsberg File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Parse xxx? as JSDoc type when not followed by token that starts type
- Loading branch information
commit c5fd2f14f38d669f604f8cb40af8f3e0d747c600
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we want to support conditional types in JSDoc for
// @ts-check
support?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We might consider that, but I'm not sure to what extent we want to permit JSDoc that is only understood type TypeScript.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We already support mapped and index types in jsdoc, right? Unless there's parse ambiguity, we should probably just continue exposing all type syntaxes in jsdoc.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In general, we want to support all Typescript types in JSDoc. The ideal is for eager Typescript users to be able to put Typescript types into jsdoc if they are stuck with vanilla javascript for some reason.
However, I think there is a conflict between the ?-suffix of jsdoc and the ? of the conditional. For example,
S extends JSDocType? ? never : any
has both, but the parser will be unable to tell whether the first ? is a suffix or part of the conditional syntax.I could be wrong, though! It’s really difficult to guess how the parser will behave without testing it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can always make the jsdoc postfix ? have a no-whitespace requirement and make the conditional ? have required whitespace in jsdoc to disambiguate, should it be ambiguous, yeah?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Or we can do speculative parsing to see whether we can parse it as a ConditionalType (e.g. try to parse a true branch) and then fall back to postfix-
?