From 0f3a561fc4996289c06127561e3ffb1bdbc811f5 Mon Sep 17 00:00:00 2001 From: Eric Traut Date: Sun, 20 Oct 2024 13:40:15 -0700 Subject: [PATCH] Fixed a bug that results in a spurious error when specializing an old-style generic type alias whose type is defined as a new-style type alias that has multiple type parameters, only some of which are used in its type definition. This addresses #9273. --- .../src/analyzer/typeUtils.ts | 20 ++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/packages/pyright-internal/src/analyzer/typeUtils.ts b/packages/pyright-internal/src/analyzer/typeUtils.ts index 0f93683e9b44..82423da350f1 100644 --- a/packages/pyright-internal/src/analyzer/typeUtils.ts +++ b/packages/pyright-internal/src/analyzer/typeUtils.ts @@ -2004,14 +2004,24 @@ export function getTypeVarArgsRecursive(type: Type, recursionCount = 0): TypeVar recursionCount++; const aliasInfo = type.props?.typeAliasInfo; - if (aliasInfo?.typeArgs) { + if (aliasInfo) { const combinedList: TypeVarType[] = []; - aliasInfo?.typeArgs.forEach((typeArg) => { - addTypeVarsToListIfUnique(combinedList, getTypeVarArgsRecursive(typeArg, recursionCount)); - }); + if (aliasInfo.typeArgs) { + aliasInfo?.typeArgs.forEach((typeArg) => { + addTypeVarsToListIfUnique(combinedList, getTypeVarArgsRecursive(typeArg, recursionCount)); + }); - return combinedList; + return combinedList; + } + + if (aliasInfo.shared.typeParams) { + aliasInfo.shared.typeParams.forEach((typeParam) => { + addTypeVarsToListIfUnique(combinedList, [typeParam]); + }); + + return combinedList; + } } if (isTypeVar(type)) {