Skip to content

Commit 0b2d40a

Browse files
committed
feat: add widened type declarations for generic parameters in suggestions
1 parent c7d209c commit 0b2d40a

1 file changed

Lines changed: 9 additions & 1 deletion

File tree

src/utils.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,15 @@ export function getSharedTypeDeclarations(dataTypes?: DataType[], genericType: s
9090
`type ${dt.identifier}${(dt.genericKeys?.length ?? 0) > 0 ? `<${dt.genericKeys?.join(",")}>` : ""} = ${dt.type};`
9191
).join("\n");
9292

93-
return `${useGenericDeclarations ? genericDeclarations : ""}\n${typeAliasDeclarations}`;
93+
// Pre-instantiate every generic type with `any` for each type parameter.
94+
// These are used by widenForSuggestions to produce the widened type for
95+
// suggestion-scope checks when a parameter type has free TypeParameters.
96+
const widenedDeclarations = dataTypes
97+
?.filter(dt => (dt.genericKeys?.length ?? 0) > 0)
98+
.map(dt => `declare const __widen_${dt.identifier}: ${dt.identifier}<${dt.genericKeys!.map(() => "any").join(", ")}>;`)
99+
.join("\n") ?? "";
100+
101+
return `${useGenericDeclarations ? genericDeclarations : ""}\n${typeAliasDeclarations}\n${widenedDeclarations}`;
94102
}
95103

96104
/**

0 commit comments

Comments
 (0)