Class expressions#3568
Merged
Merged
Conversation
Member
There was a problem hiding this comment.
Can you make this !!node so this never returns undefined?
Member
Author
There was a problem hiding this comment.
There's no need to, undefined is just as good.
Contributor
|
👍 |
|
Should typeof operator works with class expressions? |
Member
Author
|
@xLama It works, but var B = class {}
function foo(a:typeof B):void{}
foo(B); // Ok |
|
@ahejlsberg |
Member
Author
|
@xLama Exactly. |
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
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.
This PR adds type checking for class expressions, finishing the work started in #2567.
In a class expression, the class name is optional and, if specified, is only in scope in the class expression itself. This is similar to the optional name of a function expression. It is not possible to refer to the class instance type of a class expression outside the class expression, but the type can of course be matched structurally.
Class declarations and class expressions differ as follows:
class C { }introduces an instance type namedCand a constructor function namedCwith the typenew () => C.class C { }produces a constructor function value of typenew () => Cand introduces an instance type namedCthat is in scope only within the body of the class expression.class { }produces a constructor function value of typenew () => { ... }where{ ... }is the anonymous instance type of the class expression.An example:
Fixes #497.