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); 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();