You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/compiler/checker.ts
+11Lines changed: 11 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -31974,6 +31974,17 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
31974
31974
function isReturnExpressionLiteralContext(node: Node) {
31975
31975
const ancestor = findAncestor(node, n => {
31976
31976
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;
0 commit comments