-
Notifications
You must be signed in to change notification settings - Fork 12.9k
Polymorphic 'this' type #4910
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
Merged
Merged
Polymorphic 'this' type #4910
Changes from 1 commit
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
9438a4b
Polymorphic "this" type
ahejlsberg 89ea067
Accepting new baselines
ahejlsberg 06a250e
Commenting out broken fourslash tests
ahejlsberg 285483d
Merge branch 'master' into polymorphicThisType
ahejlsberg 7acb9dd
Adding comments and addressing CR feedback
ahejlsberg 8fd2d7a
Properly emit "this" type in declaration files
ahejlsberg 9dee875
Add additional "this" containers
ahejlsberg d79f5a6
Removing a few "this" containers
ahejlsberg 41f8aad
Write "this" as "any" when "this" reference would be an error
ahejlsberg 31eebbf
Rewrite inaccessible "this" to containing class/interface in declarat…
ahejlsberg f17875e
Properly classify "this" and "await" in isExpression
ahejlsberg 9594835
Accepting new baselines
ahejlsberg 47c9190
Proper handling of "this" in getSymbolAtLocation
ahejlsberg abd2a85
Adding tests
ahejlsberg 29f6036
Fixing comment and error message per CR feedback
ahejlsberg 19319b2
Adding test for declaration files
ahejlsberg 5dc8402
Make tuple type itself the 'this' type of base array type
ahejlsberg 1c9fae8
Add tuple type test
ahejlsberg 24f906a
Error when emitted type in declaration file references inaccessible '…
ahejlsberg 81934ab
Accepting new baselines
ahejlsberg 82c010e
Adding contextual typing test
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
Next
Next commit
Polymorphic "this" type
- Loading branch information
commit 9438a4bce0375e30eaf2a01bb1d73536d8cd36e1
There are no files selected for viewing
This file contains hidden or 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
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -376,6 +376,7 @@ namespace ts { | |
OctalLiteral = 0x00010000, // Octal numeric literal | ||
Namespace = 0x00020000, // Namespace declaration | ||
ExportContext = 0x00040000, // Export context (initialized by binding) | ||
ContainsThis = 0x00080000, // Contains reference to "this" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Clarify that this flag only applies to interfaces |
||
|
||
Modifier = Export | Ambient | Public | Private | Protected | Static | Abstract | Default | Async, | ||
AccessibilityModifier = Public | Private | Protected, | ||
|
@@ -1797,6 +1798,7 @@ namespace ts { | |
/* @internal */ | ||
ContainsAnyFunctionType = 0x00800000, // Type is or contains object literal type | ||
ESSymbol = 0x01000000, // Type of symbol primitive introduced in ES6 | ||
ThisType = 0x02000000, // This type | ||
|
||
/* @internal */ | ||
Intrinsic = Any | String | Number | Boolean | ESSymbol | Void | Undefined | Null, | ||
|
@@ -1842,6 +1844,7 @@ namespace ts { | |
typeParameters: TypeParameter[]; // Type parameters (undefined if non-generic) | ||
outerTypeParameters: TypeParameter[]; // Outer type parameters (undefined if none) | ||
localTypeParameters: TypeParameter[]; // Local type parameters (undefined if none) | ||
thisType: TypeParameter; // The "this" type (undefined if none) | ||
/* @internal */ | ||
resolvedBaseConstructorType?: Type; // Resolved base constructor type of class | ||
/* @internal */ | ||
|
@@ -1856,10 +1859,17 @@ namespace ts { | |
declaredNumberIndexType: Type; // Declared numeric index type | ||
} | ||
|
||
// Type references (TypeFlags.Reference) | ||
// Type references (TypeFlags.Reference). When a class or interface has type parameters or | ||
// a "this" type, references to the class or interface are made using type references. The | ||
// typeArguments property specififes the types to substitute for the type parameters of the | ||
// class or interface and optionally includes an extra element that specifies the type to | ||
// substitute for "this" in the resulting instantiation. When no extra argument is present, | ||
// the type reference itself is substituted for "this". The typeArguments property is undefined | ||
// if the class or interface has no type parameters and the reference isn't specifying an | ||
// explicit "this" argument. | ||
export interface TypeReference extends ObjectType { | ||
target: GenericType; // Type reference target | ||
typeArguments: Type[]; // Type reference type arguments | ||
typeArguments: Type[]; // Type reference type arguments (undefined if none) | ||
} | ||
|
||
// Generic class and interface types | ||
|
This file contains hidden or 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
This file contains hidden or 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.
A 'this' type annotation is only allowed in a non-static member of a class or interface.
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.
No, this isn't about type annotations, this is about references to the
this
type (which might or might not occur in type annotations, for example the reference could be in a type assertion).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. Le 8000 arn more.
Then perhaps just make it
A 'this' type is only allowed...
because that follows the intended naming conventions.