Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Always report unmeasurable variance for mapped types #49894

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19978,7 +19978,7 @@ namespace ts {
if (modifiersRelated) {
let result: Ternary;
const targetConstraint = getConstraintTypeFromMappedType(target);
const sourceConstraint = instantiateType(getConstraintTypeFromMappedType(source), getCombinedMappedTypeOptionality(source) < 0 ? reportUnmeasurableMapper : reportUnreliableMapper);
const sourceConstraint = instantiateType(getConstraintTypeFromMappedType(source), reportUnmeasurableMapper);
if (result = isRelatedTo(targetConstraint, sourceConstraint, RecursionFlags.Both, reportErrors)) {
const mapper = createTypeMapper([getTypeParameterFromMappedType(source)], [getTypeParameterFromMappedType(target)]);
if (instantiateType(getNameTypeFromMappedType(source), mapper) === instantiateType(getNameTypeFromMappedType(target), mapper)) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
tests/cases/compiler/consistentAliasVsNonAliasRecordBehavior.ts(10,5): error TS2741: Property 'a' is missing in type 'Record<string, string>' but required in type 'Record<"a", string>'.
tests/cases/compiler/consistentAliasVsNonAliasRecordBehavior.ts(14,5): error TS2741: Property 'a' is missing in type 'Record2<string, string>' but required in type 'Record2<"a", string>'.
tests/cases/compiler/consistentAliasVsNonAliasRecordBehavior.ts(18,5): error TS2741: Property 'a' is missing in type 'Record<string, string>' but required in type 'Record2<"a", string>'.
tests/cases/compiler/consistentAliasVsNonAliasRecordBehavior.ts(22,5): error TS2741: Property 'a' is missing in type 'Record2<string, string>' but required in type 'Record<"a", string>'.
tests/cases/compiler/consistentAliasVsNonAliasRecordBehavior.ts(26,5): error TS2741: Property 'a' is missing in type 'Record<string, T>' but required in type 'Record<"a", T>'.
tests/cases/compiler/consistentAliasVsNonAliasRecordBehavior.ts(30,5): error TS2741: Property 'a' is missing in type 'Record2<string, T>' but required in type 'Record2<"a", T>'.
tests/cases/compiler/consistentAliasVsNonAliasRecordBehavior.ts(34,5): error TS2741: Property 'a' is missing in type 'Record<string, T>' but required in type 'Record2<"a", T>'.
tests/cases/compiler/consistentAliasVsNonAliasRecordBehavior.ts(38,5): error TS2741: Property 'a' is missing in type 'Record2<string, T>' but required in type 'Record<"a", T>'.


==== tests/cases/compiler/consistentAliasVsNonAliasRecordBehavior.ts (4 errors) ====
==== tests/cases/compiler/consistentAliasVsNonAliasRecordBehavior.ts (8 errors) ====
// TODO: FIXME: All the below cases labeled `no error` _should be an error_, and are only prevented from so being
// by incorrect variance-based relationships
// Ref: https://github.com/Microsoft/TypeScript/issues/29698
Expand All @@ -15,10 +19,14 @@ tests/cases/compiler/consistentAliasVsNonAliasRecordBehavior.ts(38,5): error TS2

function defaultRecord(x: Record<'a', string>, y: Record<string, string>) {
x = y; // no error, but error expected.
~
!!! error TS2741: Property 'a' is missing in type 'Record<string, string>' but required in type 'Record<"a", string>'.
}

function customRecord(x: Record2<'a', string>, y: Record2<string, string>) {
x = y; // no error, but error expected.
~
!!! error TS2741: Property 'a' is missing in type 'Record2<string, string>' but required in type 'Record2<"a", string>'.
}

function mixed1(x: Record2<'a', string>, y: Record<string, string>) {
Expand All @@ -35,10 +43,14 @@ tests/cases/compiler/consistentAliasVsNonAliasRecordBehavior.ts(38,5): error TS2

function defaultRecord2<T>(x: Record<'a', T>, y: Record<string, T>) {
x = y; // no error, but error expected.
~
!!! error TS2741: Property 'a' is missing in type 'Record<string, T>' but required in type 'Record<"a", T>'.
}

function customRecord2<T>(x: Record2<'a', T>, y: Record2<string, T>) {
x = y; // no error, but error expected.
~
!!! error TS2741: Property 'a' is missing in type 'Record2<string, T>' but required in type 'Record2<"a", T>'.
}

function mixed3<T>(x: Record2<'a', T>, y: Record<string, T>) {
Expand Down