-
Notifications
You must be signed in to change notification settings - Fork 12.6k
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
String literal types #5185
Merged
Merged
String literal types #5185
Changes from 1 commit
Commits
Show all changes
44 commits
Select commit
Hold shift + click to select a range
311a0cf
Added tests.
DanielRosenwasser 911e907
Added test for string literal types in type arguments.
DanielRosenwasser f04cc39
Accepted baselines.
DanielRosenwasser 191be4f
Make string literals valid constituent types nodes in the parser.
DanielRosenwasser 84786d8
Accepted baselines.
DanielRosenwasser dc0e368
Make string literals valid types in type lists.
DanielRosenwasser 8891fba
Accepted baselines.
DanielRosenwasser 82545ce
Added test for string types in tuples.
DanielRosenwasser ed927d8
Accepted baselines.
DanielRosenwasser a3e7ccb
Use normalized text for text on string literal types.
DanielRosenwasser 20c2c4e
Amended fourslash tests to expect double quotes.
DanielRosenwasser 87f2957
Accepted baselines.
DanielRosenwasser f721971
Capture compatible contextual types for unions containing string lite…
DanielRosenwasser 7b4e94d
Accepted baselines.
DanielRosenwasser d8d72aa
Separated the concept of apparent types from contextual types for str…
DanielRosenwasser 315b06d
Accepted baselines.
DanielRosenwasser 4b736da
Fixed issue in test.
DanielRosenwasser fd5dec4
Accepted baselines.
DanielRosenwasser f7a6ac7
Added more tests.
DanielRosenwasser a440f06
Accepted baselines.
DanielRosenwasser d2e2a55
Added fourslash test.
DanielRosenwasser 6e3343c
Merge branch 'master' into stringLiteralTypes
DanielRosenwasser 74ac57d
Accepted post-merge baselines.
DanielRosenwasser 61ece76
Return the string literal type itself instead of the union type.
DanielRosenwasser 84b64c4
Accepted baselines.
DanielRosenwasser 3788254
Semicolon.
DanielRosenwasser ebc47d5
Linting.
DanielRosenwasser 725bda8
Merge branch 'master' into stringLiteralTypes
DanielRosenwasser ec0d49a
Always use a string literal type if contextually typed by any string …
DanielRosenwasser 1dbd8d1
Accepted baselines.
DanielRosenwasser 307d73e
Merge branch 'master' into stringLiteralTypes
DanielRosenwasser 049d02f
Merge branch 'master' into stringLiteralTypes
DanielRosenwasser 6618fd2
Added tests for operations that use assignable to/from.
DanielRosenwasser bf4880a
Merge branch 'master' into stringLiteralTypes
DanielRosenwasser 5e23143
Accepted baselines.
DanielRosenwasser 8dbfe1c
Added specific checks for comparing stringlike types.
DanielRosenwasser a1fcfaf
Accepted baselines.
DanielRosenwasser bb232f7
Merge remote-tracking branch 'origin/master' into stringLiteralTypes
DanielRosenwasser f939ff2
Fixed unreachable code in tests.
DanielRosenwasser d234b8d
Accepted baselines.
DanielRosenwasser c011ed4
Const.
DanielRosenwasser 38090c6
Added tests for template strings with string literal types.
DanielRosenwasser d294524
Accepted baselines.
DanielRosenwasser ea4e21d
Fixed comments.
DanielRosenwasser 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
Separated the concept of apparent types from contextual types for str…
…ing literal types. In most cases, expressions are interested in the apparent type of the contextual type. For instance: var x = { hasOwnProperty(prop) { /* ... */ }; In the above, 'prop' should be contextually typed as 'string' from the signature of 'hasOwnProperty' in the global 'Object' type. However, in the case of string literal types, we don't want to get the apparent type after fetching the contextual type. This is because the apparent type of the '"onload"' string literal type is the global 'String' type. This has adverse effects in simple assignments like the following: let x: "onload" = "onload"; In this example, the right-hand side of the assignment will grab the type of 'x'. After figuring out the type is "onload", we then get the apparent type which is 'String'. This is problematic because when we then check the assignment itself, 'String's are not assignable to '"onload"'s. So in this case, we grab the contextual type *without* getting its apparent type.
- Loading branch information
commit d8d72aabae439e17d18e35887981165413b71556
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.
Yeah... that was why I named it Worker...
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.
Ah, that makes sense, though it feels strange to get the actual contextual type when its name is worker. If you think it'd be better to rename it back to worker, I can do that.
I also suspect that we could shave off some time by using this function (instead of
getApparentTypeOfContextualType
) for array literals as well. I'll probably do it as part of another change.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.
The idea (however it is achieved) is to make the apparent type the default behavior when you don't specify anything. Getting the contextual type without its apparent type is quite an odd thing to do, so I prefer that to be the marked form. You can also call them getContextualType and getContextualTypeWithoutApparentType.