Skip to content

Commit 3da4886

Browse files
authored
Fixed an issue with quickInfo crashing on a function property returned from generic function (#49049)
1 parent ec9f6a4 commit 3da4886

4 files changed

+51
-1
lines changed

src/compiler/checker.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11340,7 +11340,18 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
1134011340

1134111341
// The outer type parameters are those defined by enclosing generic classes, methods, or functions.
1134211342
function getOuterTypeParametersOfClassOrInterface(symbol: Symbol): TypeParameter[] | undefined {
11343-
const declaration = symbol.flags & SymbolFlags.Class ? symbol.valueDeclaration : getDeclarationOfKind(symbol, SyntaxKind.InterfaceDeclaration)!;
11343+
const declaration = (symbol.flags & SymbolFlags.Class || symbol.flags & SymbolFlags.Function)
11344+
? symbol.valueDeclaration
11345+
: symbol.declarations?.find(decl => {
11346+
if (decl.kind === SyntaxKind.InterfaceDeclaration) {
11347+
return true;
11348+
}
11349+
if (decl.kind !== SyntaxKind.VariableDeclaration) {
11350+
return false;
11351+
}
11352+
const initializer = (decl as VariableDeclaration).initializer;
11353+
return !!initializer && (initializer.kind === SyntaxKind.FunctionExpression || initializer.kind === SyntaxKind.ArrowFunction);
11354+
})!;
1134411355
Debug.assert(!!declaration, "Class was missing valueDeclaration -OR- non-class had no interface declarations");
1134511356
return getOuterTypeParameters(declaration);
1134611357
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
/// <reference path="fourslash.ts" />
2+
3+
//// function createProps<T>(t: T) {
4+
//// function getProps() {}
5+
//// function createVariants() {}
6+
////
7+
//// getProps.createVariants = createVariants;
8+
//// return getProps;
9+
//// }
10+
////
11+
//// createProps({})./**/createVariants();
12+
13+
verify.quickInfoAt("", "(property) getProps<{}>.createVariants: () => void");
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
/// <reference path="fourslash.ts" />
2+
3+
//// function createProps<T>(t: T) {
4+
//// const getProps = function() {}
5+
//// const createVariants = function() {}
6+
////
7+
//// getProps.createVariants = createVariants;
8+
//// return getProps;
9+
//// }
10+
////
11+
//// createProps({})./**/createVariants();
12+
13+
verify.quickInfoAt("", "(property) getProps<{}>.createVariants: () => void");
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
/// <reference path="fourslash.ts" />
2+
3+
//// function createProps<T>(t: T) {
4+
//// const getProps = () => {}
5+
//// const createVariants = () => {}
6+
////
7+
//// getProps.createVariants = createVariants;
8+
//// return getProps;
9+
//// }
10+
////
11+
//// createProps({})./**/createVariants();
12+
13+
verify.quickInfoAt("", "(property) getProps<{}>.createVariants: () => void");

0 commit comments

Comments
 (0)