Skip to content

Fix debug assert in getConstructorDefinedThisAssignmentTypes #52321

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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;
Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
@@ -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"
}
]
}
}
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/// <reference path="fourslash.ts" />

// @noLib: true
// @allowJs: true
// @filename: /test.js
////class Foo {
//// constructor() {
//// this.prop = { };
//// }
////
//// declare prop: string;
//// method() {
//// this.prop.foo/**/
//// }
////}

verify.baselineQuickInfo();