Skip to content

Commit 6684e3d

Browse files
authoredDec 7, 2022
Fixed substition types for non-generic indexed accesses (#51621)
1 parent 832a6e4 commit 6684e3d

4 files changed

+23
-2
lines changed
 

‎src/compiler/checker.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -15020,8 +15020,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
1502015020
}
1502115021

1502215022
function getSubstitutionType(baseType: Type, constraint: Type) {
15023-
if (constraint.flags & TypeFlags.AnyOrUnknown || constraint === baseType ||
15024-
!isGenericType(baseType) && !isGenericType(constraint)) {
15023+
if (constraint.flags & TypeFlags.AnyOrUnknown || constraint === baseType) {
1502515024
return baseType;
1502615025
}
1502715026
const id = `${getTypeId(baseType)}>${getTypeId(constraint)}`;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
=== tests/cases/compiler/substitutionTypeForNonGenericIndexedAccessType.ts ===
2+
interface A {}
3+
>A : Symbol(A, Decl(substitutionTypeForNonGenericIndexedAccessType.ts, 0, 0))
4+
5+
type B = A extends Record<'foo', string> ? A['foo'] : string; // no error
6+
>B : Symbol(B, Decl(substitutionTypeForNonGenericIndexedAccessType.ts, 0, 14))
7+
>A : Symbol(A, Decl(substitutionTypeForNonGenericIndexedAccessType.ts, 0, 0))
8+
>Record : Symbol(Record, Decl(lib.es5.d.ts, --, --))
9+
>A : Symbol(A, Decl(substitutionTypeForNonGenericIndexedAccessType.ts, 0, 0))
10+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
=== tests/cases/compiler/substitutionTypeForNonGenericIndexedAccessType.ts ===
2+
interface A {}
3+
4+
type B = A extends Record<'foo', string> ? A['foo'] : string; // no error
5+
>B : string
6+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
// @strict: true
2+
// @noEmit: true
3+
4+
interface A {}
5+
6+
type B = A extends Record<'foo', string> ? A['foo'] : string; // no error

0 commit comments

Comments
 (0)