Skip to content

Commit dcbb2e5

Browse files
committed
Add a comment for isInferentialContext
1 parent a660d7b commit dcbb2e5

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

src/compiler/checker.ts

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6700,8 +6700,21 @@ namespace ts {
67006700
return result;
67016701
}
67026702

6703-
// Presence of a contextual type mapper indicates inferential typing, except the identityMapper object is
6704-
// used as a special marker for other purposes.
6703+
/**
6704+
* Detect if the mapper implies an inference context. Specifically, there are 4 possible values
6705+
* for a mapper. Let's go through each one of them:
6706+
*
6707+
* 1. undefined - this means we are not doing inferential typing, but we may do contextual typing,
6708+
* which could cause us to assign a parameter type
6709+
* 2. identityMapper - means we want to avoid assigning a parameter type, whether or not we are in
6710+
* inferential typing (context is undefined for the identityMapper)
6711+
* 3. a mapper created by createInferenceMapper - we are doing inferential typing, we want to assign
6712+
* parameter types and fix type parameters (context is defined)
6713+
* 4. an instantiation mapper created by createTypeMapper or createTypeEraser - this should never be
6714+
* passed as the contextual mapper when checking an expression (context is undefined for these)
6715+
*
6716+
* isInferentialContext is detecting if we are in case 3
6717+
*/
67056718
function isInferentialContext(mapper: TypeMapper) {
67066719
return mapper && mapper.context;
67076720
}

0 commit comments

Comments
 (0)