mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-02-05 16:38:05 -06:00
Fix completions in return when in function with contextual 'this' (#45340)
This commit is contained in:
parent
c0796c1dfb
commit
4fc4c18299
@ -1602,6 +1602,12 @@ namespace ts.Completions {
|
||||
}
|
||||
|
||||
if (!isTypeLocation) {
|
||||
// GH#39946. Pulling on the type of a node inside of a function with a contextual `this` parameter can result in a circularity
|
||||
// if the `node` is part of the exprssion of a `yield` or `return`. This circularity doesn't exist at compile time because
|
||||
// we will check (and cache) the type of `this` *before* checking the type of the node.
|
||||
const container = getThisContainer(node, /*includeArrowFunctions*/ false);
|
||||
if (!isSourceFile(container) && container.parent) typeChecker.getTypeAtLocation(container);
|
||||
|
||||
let type = typeChecker.getTypeAtLocation(node).getNonOptionalType();
|
||||
let insertQuestionDot = false;
|
||||
if (type.isNullableType()) {
|
||||
|
||||
@ -0,0 +1,31 @@
|
||||
/// <reference path="fourslash.ts" />
|
||||
|
||||
////interface Ctx {
|
||||
//// foo(): {
|
||||
//// x: number
|
||||
//// };
|
||||
////}
|
||||
////
|
||||
////declare function wrap(cb: (this: Ctx) => any): void;
|
||||
////
|
||||
////wrap(function () {
|
||||
//// const xs = this.foo();
|
||||
//// return xs./*inReturn*/
|
||||
////});
|
||||
////
|
||||
////wrap(function () {
|
||||
//// const xs = this.foo();
|
||||
//// const y = xs./*involvedInReturn*/
|
||||
//// return y;
|
||||
////});
|
||||
|
||||
verify.completions(
|
||||
{
|
||||
marker: "inReturn",
|
||||
exact: ["x"],
|
||||
},
|
||||
{
|
||||
marker: "involvedInReturn",
|
||||
exact: ["x"],
|
||||
},
|
||||
);
|
||||
Loading…
x
Reference in New Issue
Block a user