File tree Expand file tree Collapse file tree 2 files changed +37
-0
lines changed
Expand file tree Collapse file tree 2 files changed +37
-0
lines changed Original file line number Diff line number Diff line change @@ -1602,6 +1602,12 @@ namespace ts.Completions {
16021602 }
16031603
16041604 if ( ! isTypeLocation ) {
1605+ // GH#39946. Pulling on the type of a node inside of a function with a contextual `this` parameter can result in a circularity
1606+ // if the `node` is part of the exprssion of a `yield` or `return`. This circularity doesn't exist at compile time because
1607+ // we will check (and cache) the type of `this` *before* checking the type of the node.
1608+ const container = getThisContainer ( node , /*includeArrowFunctions*/ false ) ;
1609+ if ( ! isSourceFile ( container ) && container . parent ) typeChecker . getTypeAtLocation ( container ) ;
1610+
16051611 let type = typeChecker . getTypeAtLocation ( node ) . getNonOptionalType ( ) ;
16061612 let insertQuestionDot = false ;
16071613 if ( type . isNullableType ( ) ) {
Original file line number Diff line number Diff line change 1+ /// <reference path="fourslash.ts" />
2+
3+ ////interface Ctx {
4+ //// foo(): {
5+ //// x: number
6+ //// };
7+ //// }
8+ ////
9+ ////declare function wrap(cb: (this: Ctx) => any): void;
10+ ////
11+ ////wrap(function () {
12+ //// const xs = this.foo();
13+ //// return xs./*inReturn*/
14+ //// });
15+ ////
16+ ////wrap(function () {
17+ //// const xs = this.foo();
18+ //// const y = xs./*involvedInReturn*/
19+ //// return y;
20+ //// });
21+
22+ verify . completions (
23+ {
24+ marker : "inReturn" ,
25+ exact : [ "x" ] ,
26+ } ,
27+ {
28+ marker : "involvedInReturn" ,
29+ exact : [ "x" ] ,
30+ } ,
31+ ) ;
You can’t perform that action at this time.
0 commit comments