mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-02-06 11:54:44 -06:00
Fix 7304: show correct quickinfo on "this" in type position (#8508)
* Show correct quickinfo when using this in type position * Split quickinfo test into smaller files and add test case
This commit is contained in:
parent
955cc69c70
commit
72c19ec806
@ -5211,6 +5211,7 @@ namespace ts {
|
||||
case SyntaxKind.NullKeyword:
|
||||
return nullType;
|
||||
case SyntaxKind.ThisType:
|
||||
case SyntaxKind.ThisKeyword:
|
||||
return getTypeFromThisTypeNode(node);
|
||||
case SyntaxKind.StringLiteralType:
|
||||
return getTypeFromStringLiteralTypeNode(<StringLiteralTypeNode>node);
|
||||
@ -12509,7 +12510,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
|
||||
|
||||
@ -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:
|
||||
|
||||
@ -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) {
|
||||
@ -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');
|
||||
@ -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
tests/cases/fourslash/quickInfoOnThis2.ts
Normal file
14
tests/cases/fourslash/quickInfoOnThis2.ts
Normal file
@ -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
tests/cases/fourslash/quickInfoOnThis3.ts
Normal file
32
tests/cases/fourslash/quickInfoOnThis3.ts
Normal file
@ -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
tests/cases/fourslash/quickInfoOnThis4.ts
Normal file
20
tests/cases/fourslash/quickInfoOnThis4.ts
Normal file
@ -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');
|
||||
Loading…
x
Reference in New Issue
Block a user