-
Notifications
You must be signed in to change notification settings - Fork 12.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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
1 parent
7b4e94d
commit d8d72aa
Showing
1 changed file
with
23 additions
and
16 deletions.
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