Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5184,6 +5184,7 @@ namespace ts {
case SyntaxKind.NullKeyword:
return nullType;
case SyntaxKind.ThisType:
case SyntaxKind.ThisKeyword:
return getTypeFromThisTypeNode(node);
case SyntaxKind.StringLiteralType:
return getTypeFromStringLiteralTypeNode(<StringLiteralTypeNode>node);
Expand Down Expand Up @@ -12482,7 +12483,7 @@ namespace ts {

// Checks an expression and returns its type. The contextualMapper parameter serves two purposes: When
// contextualMapper is not undefined and not equal to the identityMapper function object it indicates that the
// expression is being inferentially typed (section 4.12.2 in spec) and provides the type mapper to use in
// expression is being inferentially typed (section 4.15.2 in spec) and provides the type mapper to use in
// conjunction with the generic contextual type. When contextualMapper is equal to the identityMapper function
// object, it serves as an indicator that all contained function and arrow expressions should be considered to
// have the wildcard function type; this form of type check is used during overload resolution to exclude
Expand Down
1 change: 1 addition & 0 deletions src/compiler/utilities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1056,6 +1056,7 @@ namespace ts {

export function isExpression(node: Node): boolean {
switch (node.kind) {
case SyntaxKind.ThisKeyword:
case SyntaxKind.SuperKeyword:
case SyntaxKind.NullKeyword:
case SyntaxKind.TrueKeyword:
Expand Down
65 changes: 4 additions & 61 deletions tests/cases/fourslash/quickInfoOnThis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
////function wrapper(wrapped: { (): void; }) { }
////class Foo {
//// n: number;
//// prop1: th/*0*/is;
//// public explicitThis(this: this) {
//// wrapper(
//// function explicitVoid(this: void) {
Expand All @@ -20,43 +21,9 @@
//// console.log(th/*6*/is);
//// }
////}
////class Bar<T> {
//// public explicitThis(this: this) {
//// console.log(th/*7*/is);
//// }
//// public explicitClass(this: Bar<T>) {
//// console.log(thi/*8*/s);
//// }
////}
////
////function implicitAny(x: number): void {
//// return th/*9*/is;
////}
////function explicitVoid(th/*10*/is: void, x: number): void {
//// return th/*11*/is;
////}
////function explicitInterface(th/*12*/is: Restricted): void {
//// console.log(thi/*13*/s);
////}
////function explicitLiteral(th/*14*/is: { n: number }): void {
//// console.log(th/*15*/is);
////}
////
////interface ContextualInterface {
//// m: number;
//// method(this: this, n: number);
////}
////let o: ContextualInterface = {
//// m: 12,
//// method(n) {
//// let x = this/*16*/.m;
//// }
////}
////interface ContextualInterface2 {
//// (this: void, n: number): void;
////}
////let contextualInterface2: ContextualInterface2 = function (th/*17*/is, n) { }

goTo.marker('0');
verify.quickInfoIs('this: this');
goTo.marker('1');
verify.quickInfoIs('void');
goTo.marker('2');
Expand All @@ -68,28 +35,4 @@ verify.quickInfoIs('this: Restricted');
goTo.marker('5');
verify.quickInfoIs('(parameter) this: Foo');
goTo.marker('6');
verify.quickInfoIs('this: Foo');
goTo.marker('7');
verify.quickInfoIs('this: this');
goTo.marker('8');
verify.quickInfoIs('this: Bar<T>');
goTo.marker('9');
verify.quickInfoIs('any');
goTo.marker('10');
verify.quickInfoIs('(parameter) this: void');
goTo.marker('11');
verify.quickInfoIs('void');
goTo.marker('12');
verify.quickInfoIs('(parameter) this: Restricted');
goTo.marker('13');
verify.quickInfoIs('this: Restricted');
goTo.marker('14');

verify.quickInfoIs('(parameter) this: {\n n: number;\n}');
goTo.marker('15');
verify.quickInfoIs('this: {\n n: number;\n}');

goTo.marker('16');
verify.quickInfoIs('this: ContextualInterface');
goTo.marker('17');
verify.quickInfoIs('(parameter) this: void');
verify.quickInfoIs('this: Foo');
14 changes: 14 additions & 0 deletions tests/cases/fourslash/quickInfoOnThis2.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/// <reference path='fourslash.ts' />
////class Bar<T> {
//// public explicitThis(this: this) {
//// console.log(th/*1*/is);
//// }
//// public explicitClass(this: Bar<T>) {
//// console.log(thi/*2*/s);
//// }
////}

goTo.marker('1');
verify.quickInfoIs('this: this');
goTo.marker('2');
verify.quickInfoIs('this: Bar<T>');
32 changes: 32 additions & 0 deletions tests/cases/fourslash/quickInfoOnThis3.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/// <reference path='fourslash.ts' />
////interface Restricted {
//// n: number;
////}
////function implicitAny(x: number): void {
//// return th/*1*/is;
////}
////function explicitVoid(th/*2*/is: void, x: number): void {
//// return th/*3*/is;
////}
////function explicitInterface(th/*4*/is: Restricted): void {
//// console.log(thi/*5*/s);
////}
////function explicitLiteral(th/*6*/is: { n: number }): void {
//// console.log(th/*7*/is);
////}

goTo.marker('1');
verify.quickInfoIs('any');
goTo.marker('2');
verify.quickInfoIs('(parameter) this: void');
goTo.marker('3');
verify.quickInfoIs('void');
goTo.marker('4');
verify.quickInfoIs('(parameter) this: Restricted');
goTo.marker('5');
verify.quickInfoIs('this: Restricted');
goTo.marker('6');

verify.quickInfoIs('(parameter) this: {\n n: number;\n}');
goTo.marker('7');
verify.quickInfoIs('this: {\n n: number;\n}');
20 changes: 20 additions & 0 deletions tests/cases/fourslash/quickInfoOnThis4.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/// <reference path='fourslash.ts' />
////interface ContextualInterface {
//// m: number;
//// method(this: this, n: number);
////}
////let o: ContextualInterface = {
//// m: 12,
//// method(n) {
//// let x = this/*1*/.m;
//// }
////}
////interface ContextualInterface2 {
//// (this: void, n: number): void;
////}
////let contextualInterface2: ContextualInterface2 = function (th/*2*/is, n) { }

goTo.marker('1');
verify.quickInfoIs('this: ContextualInterface');
goTo.marker('2');
verify.quickInfoIs('(parameter) this: void');