Fixed an issue with quickInfo crashing on a function property returned from generic function (#49049)

This commit is contained in:
Mateusz Burzyński 2023-01-11 01:05:01 +01:00 committed by GitHub
parent ec9f6a428b
commit 3da4886c76
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 51 additions and 1 deletions

View File

@ -11340,7 +11340,18 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
// The outer type parameters are those defined by enclosing generic classes, methods, or functions.
function getOuterTypeParametersOfClassOrInterface(symbol: Symbol): TypeParameter[] | undefined {
const declaration = symbol.flags & SymbolFlags.Class ? symbol.valueDeclaration : getDeclarationOfKind(symbol, SyntaxKind.InterfaceDeclaration)!;
const declaration = (symbol.flags & SymbolFlags.Class || symbol.flags & SymbolFlags.Function)
? symbol.valueDeclaration
: symbol.declarations?.find(decl => {
if (decl.kind === SyntaxKind.InterfaceDeclaration) {
return true;
}
if (decl.kind !== SyntaxKind.VariableDeclaration) {
return false;
}
const initializer = (decl as VariableDeclaration).initializer;
return !!initializer && (initializer.kind === SyntaxKind.FunctionExpression || initializer.kind === SyntaxKind.ArrowFunction);
})!;
Debug.assert(!!declaration, "Class was missing valueDeclaration -OR- non-class had no interface declarations");
return getOuterTypeParameters(declaration);
}

View File

@ -0,0 +1,13 @@
/// <reference path="fourslash.ts" />
//// function createProps<T>(t: T) {
//// function getProps() {}
//// function createVariants() {}
////
//// getProps.createVariants = createVariants;
//// return getProps;
//// }
////
//// createProps({})./**/createVariants();
verify.quickInfoAt("", "(property) getProps<{}>.createVariants: () => void");

View File

@ -0,0 +1,13 @@
/// <reference path="fourslash.ts" />
//// function createProps<T>(t: T) {
//// const getProps = function() {}
//// const createVariants = function() {}
////
//// getProps.createVariants = createVariants;
//// return getProps;
//// }
////
//// createProps({})./**/createVariants();
verify.quickInfoAt("", "(property) getProps<{}>.createVariants: () => void");

View File

@ -0,0 +1,13 @@
/// <reference path="fourslash.ts" />
//// function createProps<T>(t: T) {
//// const getProps = () => {}
//// const createVariants = () => {}
////
//// getProps.createVariants = createVariants;
//// return getProps;
//// }
////
//// createProps({})./**/createVariants();
verify.quickInfoAt("", "(property) getProps<{}>.createVariants: () => void");