Skip to content

Commit 9055e55

Browse files
committed
add comment
1 parent 4dce1de commit 9055e55

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

src/compiler/checker.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31974,6 +31974,17 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
3197431974
function isReturnExpressionLiteralContext(node: Node) {
3197531975
const ancestor = findAncestor(node, n => {
3197631976
if (isCallOrNewExpression(n)) {
31977+
// prevent inference candidates of outer inference context to provide contextual type information for the expressions within the inner context
31978+
// that could turn fresh literal candidates in the inner context into regular types for union-like literals (such as booleans and enums)
31979+
// and that would create mismatches between inferred types for outer and inner contexts which is especially problematic when invariant type parameters are involved
31980+
//
31981+
// the call below should be ok but with the inner one receiving `boolean` as contextual type it would infer `true` for its type parameter
31982+
// and that would create outer signature applicability error with outer `Box<boolean>` and inner `Box<true>`
31983+
//
31984+
// interface Box<T> { v: (arg: T) => T; }
31985+
// declare function invariantBox<T>(v: T): Box<T>
31986+
// declare function fn<T>(arg: Box<T>, get: () => Box<T>): void;
31987+
// fn(invariantBox(true), () => invariantBox(true));
3197731988
return "quit";
3197831989
}
3197931990
const parent = n.parent;

0 commit comments

Comments
 (0)