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
Add unmeasurable variance kind for marking types whose variance result is unreliable #30416
Merged
weswigham
merged 13 commits into
microsoft:master
from
weswigham:add-unmeasurable-variance-kind
May 3, 2019
Merged
Changes from 1 commit
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
029d3db
Add unmeasurable variance kind for marking types whose variance resul…
weswigham d945aa5
Merge branch 'master' into add-unmeasurable-variance-kind
weswigham 33b6e42
Remove now-unneeded nongeneric checks
weswigham bbfb25f
Merge branch 'master' into add-unmeasurable-variance-kind
weswigham 10183d9
Merge branch 'master' into add-unmeasurable-variance-kind
weswigham 15f8c10
Add rule allowing `Readonly<any>` to be `any` instead of `{readonly […
weswigham dc40484
All Unmeasurable variances to still shortcut structural comparisons i…
weswigham 093cc72
Merge branch 'master' into add-unmeasurable-variance-kind
weswigham 4e96d98
Separate unmeasurable from unreliable to reduce the impact of this ch…
weswigham b646f28
Fix lint
weswigham 18e5656
Remove Readonly<any> -> any callout
weswigham 6a9e337
Add fix for circularity error triggered by deep signature return type…
weswigham a7fc378
Merge branch 'master' into add-unmeasurable-variance-kind
weswigham File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
61 changes: 61 additions & 0 deletions
61
tests/baselines/reference/requiredMappedTypeModifierTrumpsVariance.errors.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
tests/cases/compiler/requiredMappedTypeModifierTrumpsVariance.ts(5,1): error TS2741: Property 'a' is missing in type 'Required<{ b?: 1; x: 1; }>' but required in type 'Required<{ a?: 1; x: 1; }>'. | ||
tests/cases/compiler/requiredMappedTypeModifierTrumpsVariance.ts(6,1): error TS2741: Property 'b' is missing in type 'Required<{ a?: 1; x: 1; }>' but required in type 'Required<{ b?: 1; x: 1; }>'. | ||
tests/cases/compiler/requiredMappedTypeModifierTrumpsVariance.ts(8,3): error TS2339: Property 'b' does not exist on type 'Required<{ a?: 1; x: 1; }>'. | ||
tests/cases/compiler/requiredMappedTypeModifierTrumpsVariance.ts(9,3): error TS2339: Property 'a' does not exist on type 'Required<{ b?: 1; x: 1; }>'. | ||
tests/cases/compiler/requiredMappedTypeModifierTrumpsVariance.ts(18,1): error TS2322: Type 'Foo<{ b?: 1; x: 1; }>' is not assignable to type 'Foo<{ a?: 1; x: 1; }>'. | ||
Types of property 'a' are incompatible. | ||
Property 'a' is missing in type 'Required<{ b?: 1; x: 1; }>' but required in type 'Required<{ a?: 1; x: 1; }>'. | ||
tests/cases/compiler/requiredMappedTypeModifierTrumpsVariance.ts(19,1): error TS2322: Type 'Foo<{ a?: 1; x: 1; }>' is not assignable to type 'Foo<{ b?: 1; x: 1; }>'. | ||
Types of property 'a' are incompatible. | ||
Property 'b' is missing in type 'Required<{ a?: 1; x: 1; }>' but required in type 'Required<{ b?: 1; x: 1; }>'. | ||
tests/cases/compiler/requiredMappedTypeModifierTrumpsVariance.ts(21,6): error TS2339: Property 'b' does not exist on type 'Required<{ a?: 1; x: 1; }>'. | ||
tests/cases/compiler/requiredMappedTypeModifierTrumpsVariance.ts(22,6): error TS2339: Property 'a' does not exist on type 'Required<{ b?: 1; x: 1; }>'. | ||
|
||
|
||
==== tests/cases/compiler/requiredMappedTypeModifierTrumpsVariance.ts (8 errors) ==== | ||
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 | ||
~ | ||
!!! error TS2741: Property 'a' is missing in type 'Required<{ b?: 1; x: 1; }>' but required in type 'Required<{ a?: 1; x: 1; }>'. | ||
!!! related TS2728 tests/cases/compiler/requiredMappedTypeModifierTrumpsVariance.ts:1:21: 'a' is declared here. | ||
B = a; // Should Error | ||
~ | ||
!!! error TS2741: Property 'b' is missing in type 'Required<{ a?: 1; x: 1; }>' but required in type 'Required<{ b?: 1; x: 1; }>'. | ||
!!! related TS2728 tests/cases/compiler/requiredMappedTypeModifierTrumpsVariance.ts:2:21: 'b' is declared here. | ||
|
||
a.b; // Property 'b' does not exist on type 'Required<{ a?: 1; x: 1; }>'. | ||
~ | ||
!!! error TS2339: 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; }>'. | ||
~ | ||
!!! error TS2339: 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 | ||
~~ | ||
!!! error TS2322: Type 'Foo<{ b?: 1; x: 1; }>' is not assignable to type 'Foo<{ a?: 1; x: 1; }>'. | ||
!!! error TS2322: Types of property 'a' are incompatible. | ||
!!! error TS2322: Property 'a' is missing in type 'Required<{ b?: 1; x: 1; }>' but required in type 'Required<{ a?: 1; x: 1; }>'. | ||
!!! related TS2728 tests/cases/compiler/requiredMappedTypeModifierTrumpsVariance.ts:14:17: 'a' is declared here. | ||
BB = aa; // Should Error | ||
~~ | ||
!!! error TS2322: Type 'Foo<{ a?: 1; x: 1; }>' is not assignable to type 'Foo<{ b?: 1; x: 1; }>'. | ||
!!! error TS2322: Types of property 'a' are incompatible. | ||
!!! error TS2322: Property 'b' is missing in type 'Required<{ a?: 1; x: 1; }>' but required in type 'Required<{ b?: 1; x: 1; }>'. | ||
!!! related TS2728 tests/cases/compiler/requiredMappedTypeModifierTrumpsVariance.ts:15:17: 'b' is declared here. | ||
|
||
aa.a.b; // Property 'b' does not exist on type 'Required<{ a?: 1; x: 1; }>'. | ||
~ | ||
!!! error TS2339: 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; }>'. | ||
~ | ||
!!! error TS2339: Property 'a' does not exist on type 'Required<{ b?: 1; x: 1; }>'. |
43 changes: 43 additions & 0 deletions
43
tests/baselines/reference/requiredMappedTypeModifierTrumpsVariance.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
//// [requiredMappedTypeModifierTrumpsVariance.ts] | ||
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; }>'. | ||
|
||
//// [requiredMappedTypeModifierTrumpsVariance.js] | ||
"use strict"; | ||
exports.__esModule = true; | ||
var a = { a: 1, x: 1 }; | ||
var b = { b: 1, x: 1 }; | ||
exports.A = a; | ||
exports.B = b; | ||
exports.A = b; // Should Error | ||
exports.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; }>'. | ||
var aa = { a: { a: 1, x: 1 } }; | ||
var bb = { a: { b: 1, x: 1 } }; | ||
exports.AA = aa; | ||
exports.BB = bb; | ||
exports.AA = bb; // Should Error | ||
exports.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; }>'. |
92 changes: 92 additions & 0 deletions
92
tests/baselines/reference/requiredMappedTypeModifierTrumpsVariance.symbols
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
=== tests/cases/compiler/requiredMappedTypeModifierTrumpsVariance.ts === | ||
const a: Required<{ a?: 1; x: 1 }> = { a: 1, x: 1 }; | ||
>a : Symbol(a, Decl(requiredMappedTypeModifierTrumpsVariance.ts, 0, 5)) | ||
>Required : Symbol(Required, Decl(lib.es5.d.ts, --, --)) | ||
>a : Symbol(a, Decl(requiredMappedTypeModifierTrumpsVariance.ts, 0, 19)) | ||
>x : Symbol(x, Decl(requiredMappedTypeModifierTrumpsVariance.ts, 0, 26)) | ||
>a : Symbol(a, Decl(requiredMappedTypeModifierTrumpsVariance.ts, 0, 38)) | ||
>x : Symbol(x, Decl(requiredMappedTypeModifierTrumpsVariance.ts, 0, 44)) | ||
|
||
const b: Required<{ b?: 1; x: 1 }> = { b: 1, x: 1 }; | ||
>b : Symbol(b, Decl(requiredMappedTypeModifierTrumpsVariance.ts, 1, 5)) | ||
>Required : Symbol(Required, Decl(lib.es5.d.ts, --, --)) | ||
>b : Symbol(b, Decl(requiredMappedTypeModifierTrumpsVariance.ts, 1, 19)) | ||
>x : Symbol(x, Decl(requiredMappedTypeModifierTrumpsVariance.ts, 1, 26)) | ||
>b : Symbol(b, Decl(requiredMappedTypeModifierTrumpsVariance.ts, 1, 38)) | ||
>x : Symbol(x, Decl(requiredMappedTypeModifierTrumpsVariance.ts, 1, 44)) | ||
|
||
export let A = a; | ||
>A : Symbol(A, Decl(requiredMappedTypeModifierTrumpsVariance.ts, 2, 10)) | ||
>a : Symbol(a, Decl(requiredMappedTypeModifierTrumpsVariance.ts, 0, 5)) | ||
|
||
export let B = b; | ||
>B : Symbol(B, Decl(requiredMappedTypeModifierTrumpsVariance.ts, 3, 10)) | ||
>b : Symbol(b, Decl(requiredMappedTypeModifierTrumpsVariance.ts, 1, 5)) | ||
|
||
A = b; // Should Error | ||
>A : Symbol(A, Decl(requiredMappedTypeModifierTrumpsVariance.ts, 2, 10)) | ||
>b : Symbol(b, Decl(requiredMappedTypeModifierTrumpsVariance.ts, 1, 5)) | ||
|
||
B = a; // Should Error | ||
>B : Symbol(B, Decl(requiredMappedTypeModifierTrumpsVariance.ts, 3, 10)) | ||
>a : Symbol(a, Decl(requiredMappedTypeModifierTrumpsVariance.ts, 0, 5)) | ||
|
||
a.b; // Property 'b' does not exist on type 'Required<{ a?: 1; x: 1; }>'. | ||
>a : Symbol(a, Decl(requiredMappedTypeModifierTrumpsVariance.ts, 0, 5)) | ||
|
||
b.a; // Property 'a' does not exist on type 'Required<{ b?: 1; x: 1; }>'. | ||
>b : Symbol(b, Decl(requiredMappedTypeModifierTrumpsVariance.ts, 1, 5)) | ||
|
||
interface Foo<T> { | ||
>Foo : Symbol(Foo, Decl(requiredMappedTypeModifierTrumpsVariance.ts, 8, 4)) | ||
>T : Symbol(T, Decl(requiredMappedTypeModifierTrumpsVariance.ts, 10, 14)) | ||
|
||
a: Required<T>; | ||
>a : Symbol(Foo.a, Decl(requiredMappedTypeModifierTrumpsVariance.ts, 10, 18)) | ||
>Required : Symbol(Required, Decl(lib.es5.d.ts, --, --)) | ||
>T : Symbol(T, Decl(requiredMappedTypeModifierTrumpsVariance.ts, 10, 14)) | ||
} | ||
const aa: Foo<{ a?: 1; x: 1 }> = { a: { a: 1, x: 1 } }; | ||
>aa : Symbol(aa, Decl(requiredMappedTypeModifierTrumpsVariance.ts, 13, 5)) | ||
>Foo : Symbol(Foo, Decl(requiredMappedTypeModifierTrumpsVariance.ts, 8, 4)) | ||
>a : Symbol(a, Decl(requiredMappedTypeModifierTrumpsVariance.ts, 13, 15)) | ||
>x : Symbol(x, Decl(requiredMappedTypeModifierTrumpsVariance.ts, 13, 22)) | ||
>a : Symbol(a, Decl(requiredMappedTypeModifierTrumpsVariance.ts, 13, 34)) | ||
>a : Symbol(a, Decl(requiredMappedTypeModifierTrumpsVariance.ts, 13, 39)) | ||
>x : Symbol(x, Decl(requiredMappedTypeModifierTrumpsVariance.ts, 13, 45)) | ||
|
||
const bb: Foo<{ b?: 1; x: 1 }> = { a: { b: 1, x: 1 } }; | ||
>bb : Symbol(bb, Decl(requiredMappedTypeModifierTrumpsVariance.ts, 14, 5)) | ||
>Foo : Symbol(Foo, Decl(requiredMappedTypeModifierTrumpsVariance.ts, 8, 4)) | ||
>b : Symbol(b, Decl(requiredMappedTypeModifierTrumpsVariance.ts, 14, 15)) | ||
>x : Symbol(x, Decl(requiredMappedTypeModifierTrumpsVariance.ts, 14, 22)) | ||
>a : Symbol(a, Decl(requiredMappedTypeModifierTrumpsVariance.ts, 14, 34)) | ||
>b : Symbol(b, Decl(requiredMappedTypeModifierTrumpsVariance.ts, 14, 39)) | ||
>x : Symbol(x, Decl(requiredMappedTypeModifierTrumpsVariance.ts, 14, 45)) | ||
|
||
export let AA = aa; | ||
>AA : Symbol(AA, Decl(requiredMappedTypeModifierTrumpsVariance.ts, 15, 10)) | ||
>aa : Symbol(aa, Decl(requiredMappedTypeModifierTrumpsVariance.ts, 13, 5)) | ||
|
||
export let BB = bb; | ||
>BB : Symbol(BB, Decl(requiredMappedTypeModifierTrumpsVariance.ts, 16, 10)) | ||
>bb : Symbol(bb, Decl(requiredMappedTypeModifierTrumpsVariance.ts, 14, 5)) | ||
|
||
AA = bb; // Should Error | ||
>AA : Symbol(AA, Decl(requiredMappedTypeModifierTrumpsVariance.ts, 15, 10)) | ||
>bb : Symbol(bb, Decl(requiredMappedTypeModifierTrumpsVariance.ts, 14, 5)) | ||
|
||
BB = aa; // Should Error | ||
>BB : Symbol(BB, Decl(requiredMappedTypeModifierTrumpsVariance.ts, 16, 10)) | ||
>aa : Symbol(aa, Decl(requiredMappedTypeModifierTrumpsVariance.ts, 13, 5)) | ||
|
||
aa.a.b; // Property 'b' does not exist on type 'Required<{ a?: 1; x: 1; }>'. | ||
>aa.a : Symbol(Foo.a, Decl(requiredMappedTypeModifierTrumpsVariance.ts, 10, 18)) | ||
>aa : Symbol(aa, Decl(requiredMappedTypeModifierTrumpsVariance.ts, 13, 5)) | ||
>a : Symbol(Foo.a, Decl(requiredMappedTypeModifierTrumpsVariance.ts, 10, 18)) | ||
|
||
bb.a.a; // Property 'a' does not exist on type 'Required<{ b?: 1; x: 1; }>'. | ||
>bb.a : Symbol(Foo.a, Decl(requiredMappedTypeModifierTrumpsVariance.ts, 10, 18)) | ||
>bb : Symbol(bb, Decl(requiredMappedTypeModifierTrumpsVariance.ts, 14, 5)) | ||
>a : Symbol(Foo.a, Decl(requiredMappedTypeModifierTrumpsVariance.ts, 10, 18)) | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it possible to only report as unmeasurable when the mapped types have modifiers?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Isn't the
Record
example exactly the case of when there isn't a modifier?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep, adding the modifier check means that this will not fix #29698. But the two issues aren't exactly the same so I was wondering if there exists two distinct fixes. #29698 only really breaks because when using
string
as a key type.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was the kind of (hack) I had in mind: https://pastebin.com/n431Puhu. I have no idea if this is even feasible, or correct. I thought I'd at least play around with something rather than solely firing off random questions.