From a50fd5f988ed6264e5a65172ab29862283ba79c5 Mon Sep 17 00:00:00 2001 From: Jake Bailey <5341706+jakebailey@users.noreply.github.com> Date: Thu, 19 Jan 2023 21:28:17 -0800 Subject: [PATCH 1/2] Fix debug assert in getConstructorDefinedThisAssignmentTypes --- src/compiler/checker.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index e6ea8924e8516..1ed83f8826f55 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -10491,6 +10491,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { } if (!type) { let types: Type[] | undefined; + let declarationsForTypes: Declaration[] | undefined; if (symbol.declarations) { let jsdocType: Type | undefined; for (const declaration of symbol.declarations) { @@ -10516,7 +10517,8 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { jsdocType = getAnnotatedTypeForAssignmentDeclaration(jsdocType, expression, symbol, declaration); } if (!jsdocType) { - (types || (types = [])).push((isBinaryExpression(expression) || isCallExpression(expression)) ? getInitializerTypeFromAssignmentDeclaration(symbol, resolvedSymbol, expression, kind) : neverType); + types = append(types, (isBinaryExpression(expression) || isCallExpression(expression)) ? getInitializerTypeFromAssignmentDeclaration(symbol, resolvedSymbol, expression, kind) : neverType); + declarationsForTypes = append(declarationsForTypes, declaration); } } type = jsdocType; @@ -10525,7 +10527,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { if (!length(types)) { return errorType; // No types from any declarations :( } - let constructorTypes = definedInConstructor && symbol.declarations ? getConstructorDefinedThisAssignmentTypes(types!, symbol.declarations) : undefined; + let constructorTypes = definedInConstructor && declarationsForTypes ? getConstructorDefinedThisAssignmentTypes(types!, declarationsForTypes) : undefined; // use only the constructor types unless they were only assigned null | undefined (including widening variants) if (definedInMethod) { const propType = getTypeOfPropertyInBaseClass(symbol); From b3c27eb976d22705edc05d1bf41803a2f4d6a170 Mon Sep 17 00:00:00 2001 From: Jake Bailey <5341706+jakebailey@users.noreply.github.com> Date: Thu, 19 Jan 2023 23:24:09 -0800 Subject: [PATCH 2/2] Add test from the other PR Co-authored-by: Oleksandr T --- ...DocPropertyWithAmbientDeclaration.baseline | 39 +++++++++++++++++++ ...foOnJsDocPropertyWithAmbientDeclaration.ts | 17 ++++++++ 2 files changed, 56 insertions(+) create mode 100644 tests/baselines/reference/quickInfoOnJsDocPropertyWithAmbientDeclaration.baseline create mode 100644 tests/cases/fourslash/quickInfoOnJsDocPropertyWithAmbientDeclaration.ts diff --git a/tests/baselines/reference/quickInfoOnJsDocPropertyWithAmbientDeclaration.baseline b/tests/baselines/reference/quickInfoOnJsDocPropertyWithAmbientDeclaration.baseline new file mode 100644 index 0000000000000..cd99ac79809a8 --- /dev/null +++ b/tests/baselines/reference/quickInfoOnJsDocPropertyWithAmbientDeclaration.baseline @@ -0,0 +1,39 @@ +=== /test.js === +// class Foo { +// constructor() { +// this.prop = { }; +// } +// +// declare prop: string; +// method() { +// this.prop.foo +// ^^^ +// | ---------------------------------------------------------------------- +// | any +// | ---------------------------------------------------------------------- +// } +// } + +[ + { + "marker": { + "fileName": "/test.js", + "position": 126, + "name": "" + }, + "item": { + "kind": "", + "kindModifiers": "", + "textSpan": { + "start": 123, + "length": 3 + }, + "displayParts": [ + { + "text": "any", + "kind": "keyword" + } + ] + } + } +] \ No newline at end of file diff --git a/tests/cases/fourslash/quickInfoOnJsDocPropertyWithAmbientDeclaration.ts b/tests/cases/fourslash/quickInfoOnJsDocPropertyWithAmbientDeclaration.ts new file mode 100644 index 0000000000000..47b0bb81e20f9 --- /dev/null +++ b/tests/cases/fourslash/quickInfoOnJsDocPropertyWithAmbientDeclaration.ts @@ -0,0 +1,17 @@ +/// + +// @noLib: true +// @allowJs: true +// @filename: /test.js +////class Foo { +//// constructor() { +//// this.prop = { }; +//// } +//// +//// declare prop: string; +//// method() { +//// this.prop.foo/**/ +//// } +////} + +verify.baselineQuickInfo();