Skip to content

Commit d867225

Browse files
committed
add documentation to invokeOnce
1 parent 4dcc69a commit d867225

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

src/compiler/checker.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25297,6 +25297,19 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
2529725297
priority = savePriority;
2529825298
}
2529925299

25300+
// Ensure an inference action is performed only once for the given source and target types.
25301+
// This includes two things:
25302+
// Avoiding inferring between the same pair of source and target types,
25303+
// and avoiding circularly inferring between source and target types.
25304+
// For an example of the last, consider if we are inferring between source type
25305+
// `type Deep<T> = { next: Deep<Deep<T>> }` and target type `type Loop<U> = { next: Loop<U> }`.
25306+
// We would then infer between the types of the `next` property: `Deep<Deep<T>>` = `{ next: Deep<Deep<Deep<T>>> }` and `Loop<U>` = `{ next: Loop<U> }`.
25307+
// We will then infer again between the types of the `next` property:
25308+
// `Deep<Deep<Deep<T>>>` and `Loop<U>`, and so on, such that we would be forever inferring
25309+
// between instantiations of the same types `Deep` and `Loop`.
25310+
// In particular, we would be inferring from increasingly deep instantiations of `Deep` to `Loop`,
25311+
// such that we would go on inferring forever, even though we would never infer
25312+
// between the same pair of types.
2530025313
function invokeOnce<Source extends Type, Target extends Type>(source: Source, target: Target, action: (source: Source, target: Target) => void) {
2530125314
const key = source.id + "," + target.id;
2530225315
const status = visited && visited.get(key);

0 commit comments

Comments
 (0)