TypeScript/tests/cases/compiler/requiredMappedTypeModifierTrumpsVariance.ts
Wesley Wigham b365e657d4
Add unmeasurable variance kind for marking types whose variance result is unreliable (#30416)
* Add unmeasurable variance kind for marking types whose variance result is unreliable

* Remove now-unneeded nongeneric checks

* Add rule allowing `Readonly<any>` to be `any` instead of `{readonly [index: string]: any}`

* All Unmeasurable variances to still shortcut structural comparisons in some cases

* Separate unmeasurable from unreliable to reduce the impact of this change, for now

* Fix lint

* Remove Readonly<any> -> any callout

* Add fix for circularity error triggered by deep signature return type comparisons with `this` types
2019-05-03 14:42:17 -07:00

22 lines
756 B
TypeScript

const a: Required<{ a?: 1; x: 1 }> = { a: 1, x: 1 };
const b: Required<{ b?: 1; x: 1 }> = { b: 1, x: 1 };
export let A = a;
export let B = b;
A = b; // Should Error
B = a; // Should Error
a.b; // Property 'b' does not exist on type 'Required<{ a?: 1; x: 1; }>'.
b.a; // Property 'a' does not exist on type 'Required<{ b?: 1; x: 1; }>'.
interface Foo<T> {
a: Required<T>;
}
const aa: Foo<{ a?: 1; x: 1 }> = { a: { a: 1, x: 1 } };
const bb: Foo<{ b?: 1; x: 1 }> = { a: { b: 1, x: 1 } };
export let AA = aa;
export let BB = bb;
AA = bb; // Should Error
BB = aa; // Should Error
aa.a.b; // Property 'b' does not exist on type 'Required<{ a?: 1; x: 1; }>'.
bb.a.a; // Property 'a' does not exist on type 'Required<{ b?: 1; x: 1; }>'.