Skip to content

Commit 15f8c10

Browse files
committed
Add rule allowing Readonly<any> to be any instead of {readonly [index: string]: any}
1 parent 10183d9 commit 15f8c10

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

src/compiler/checker.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11206,7 +11206,11 @@ namespace ts {
1120611206
return mapType(mappedTypeVariable, t => {
1120711207
if (t.flags & (TypeFlags.AnyOrUnknown | TypeFlags.InstantiableNonPrimitive | TypeFlags.Object | TypeFlags.Intersection) && t !== wildcardType && t !== errorType) {
1120811208
const replacementMapper = createReplacementMapper(typeVariable, t, mapper);
11209-
return isArrayType(t) ? instantiateMappedArrayType(t, type, replacementMapper) :
11209+
// The first rule exists such that `Readonly<any>` is simply `any`, which is what most people think it will resolve to.
11210+
// Without the extra special callout, it actually instantiates to `{readonly [index: string]: any}` which has a bunch of
11211+
// assignability quirks to do with index signatures - most notably it no longer provides _every possible explicit property_.
11212+
return isTypeAny(t) && getTemplateTypeFromMappedType(type) === getIndexedAccessType(typeVariable, getTypeParameterFromMappedType(type)) ? t :
11213+
isArrayType(t) ? instantiateMappedArrayType(t, type, replacementMapper) :
1121011214
isTupleType(t) ? instantiateMappedTupleType(t, type, replacementMapper) :
1121111215
instantiateAnonymousType(type, replacementMapper);
1121211216
}

0 commit comments

Comments
 (0)