add export

This commit is contained in:
Joeri Exelmans 2025-05-19 19:39:37 +02:00
parent 4fcfea409a
commit 8cfbd6116f
2 changed files with 11 additions and 3 deletions

2
index.d.ts vendored
View file

@ -342,6 +342,8 @@ export function prodType(typeParam: any): any;
export function recomputeTypeVars(types: any, skip: number): any; export function recomputeTypeVars(types: any, skip: number): any;
export function recomputeTypeVarsWithInverse(types: any, skip: number): [any, Map<string, string>];
export function setType(typeParam: any): any; export function setType(typeParam: any): any;
export function structType(fields: any, rootSelf: any): any; export function structType(fields: any, rootSelf: any): any;

View file

@ -93,16 +93,22 @@ export const assignFn = (funType, paramType, skip=0) => {
// Ensures that no type variables overlap // Ensures that no type variables overlap
export const recomputeTypeVars = (types, skip=0) => { export const recomputeTypeVars = (types, skip=0) => {
return recomputeTypeVarsWithInverse(types, skip)[0];
};
export const recomputeTypeVarsWithInverse = (types, skip=0) => {
let nextIdx = skip; let nextIdx = skip;
return types.map(type => { const inverse = new Map();
return [types.map(type => {
const substitutions = new Map(); const substitutions = new Map();
const typeVars = occurring(type); const typeVars = occurring(type);
for (const typeVar of typeVars) { for (const typeVar of typeVars) {
const idx = nextIdx++; const idx = nextIdx++;
if (typeVar !== UNBOUND_SYMBOLS[idx]) { if (typeVar !== UNBOUND_SYMBOLS[idx]) {
substitutions.set(typeVar, TYPE_VARS[idx]); substitutions.set(typeVar, TYPE_VARS[idx]);
inverse.set(UNBOUND_SYMBOLS[idx], typeVar);
} }
} }
return substitute(type, substitutions); return substitute(type, substitutions);
}); }), inverse];
}; }