-
Notifications
You must be signed in to change notification settings - Fork 12.9k
Use homomorphic templated type for Omit #42524
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
Closed
Closed
Changes from 1 commit
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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
13 changes: 13 additions & 0 deletions
13
tests/baselines/reference/omitOfTypeExtendingIndexSignature.js
This file contains hidden or 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,13 @@ | ||
//// [omitOfTypeExtendingIndexSignature.ts] | ||
// #36981 | ||
type AnyRecord = Record<string, any>; | ||
interface ExtendsAny extends AnyRecord { | ||
myKey1: string; | ||
myKey2: string; | ||
} | ||
|
||
type OmitsKey = Omit<ExtendsAny, "myKey2">; | ||
type OmitsKey1 = OmitsKey["myKey1"]; // should be `string` | ||
type OmitsKey2 = OmitsKey["myKey2"]; // should be `any` | ||
|
||
//// [omitOfTypeExtendingIndexSignature.js] |
30 changes: 30 additions & 0 deletions
30
tests/baselines/reference/omitOfTypeExtendingIndexSignature.symbols
This file contains hidden or 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,30 @@ | ||
=== tests/cases/compiler/omitOfTypeExtendingIndexSignature.ts === | ||
// #36981 | ||
type AnyRecord = Record<string, any>; | ||
>AnyRecord : Symbol(AnyRecord, Decl(omitOfTypeExtendingIndexSignature.ts, 0, 0)) | ||
>Record : Symbol(Record, Decl(lib.es5.d.ts, --, --)) | ||
|
||
interface ExtendsAny extends AnyRecord { | ||
>ExtendsAny : Symbol(ExtendsAny, Decl(omitOfTypeExtendingIndexSignature.ts, 1, 37)) | ||
>AnyRecord : Symbol(AnyRecord, Decl(omitOfTypeExtendingIndexSignature.ts, 0, 0)) | ||
|
||
myKey1: string; | ||
>myKey1 : Symbol(ExtendsAny.myKey1, Decl(omitOfTypeExtendingIndexSignature.ts, 2, 40)) | ||
|
||
myKey2: string; | ||
>myKey2 : Symbol(ExtendsAny.myKey2, Decl(omitOfTypeExtendingIndexSignature.ts, 3, 19)) | ||
} | ||
|
||
type OmitsKey = Omit<ExtendsAny, "myKey2">; | ||
>OmitsKey : Symbol(OmitsKey, Decl(omitOfTypeExtendingIndexSignature.ts, 5, 1)) | ||
>Omit : Symbol(Omit, Decl(lib.es5.d.ts, --, --)) | ||
>ExtendsAny : Symbol(ExtendsAny, Decl(omitOfTypeExtendingIndexSignature.ts, 1, 37)) | ||
|
||
type OmitsKey1 = OmitsKey["myKey1"]; // should be `string` | ||
>OmitsKey1 : Symbol(OmitsKey1, Decl(omitOfTypeExtendingIndexSignature.ts, 7, 43)) | ||
>OmitsKey : Symbol(OmitsKey, Decl(omitOfTypeExtendingIndexSignature.ts, 5, 1)) | ||
|
||
type OmitsKey2 = OmitsKey["myKey2"]; // should be `any` | ||
>OmitsKey2 : Symbol(OmitsKey2, Decl(omitOfTypeExtendingIndexSignature.ts, 8, 36)) | ||
>OmitsKey : Symbol(OmitsKey, Decl(omitOfTypeExtendingIndexSignature.ts, 5, 1)) | ||
|
22 changes: 22 additions & 0 deletions
22
tests/baselines/reference/omitOfTypeExtendingIndexSignature.types
This file contains hidden or 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,22 @@ | ||
=== tests/cases/compiler/omitOfTypeExtendingIndexSignature.ts === | ||
// #36981 | ||
type AnyRecord = Record<string, any>; | ||
>AnyRecord : AnyRecord | ||
|
||
interface ExtendsAny extends AnyRecord { | ||
myKey1: string; | ||
>myKey1 : string | ||
|
||
myKey2: string; | ||
>myKey2 : string | ||
} | ||
|
||
type OmitsKey = Omit<ExtendsAny, "myKey2">; | ||
>OmitsKey : Omit<ExtendsAny, "myKey2"> | ||
|
||
type OmitsKey1 = OmitsKey["myKey1"]; // should be `string` | ||
>OmitsKey1 : string | ||
|
||
type OmitsKey2 = OmitsKey["myKey2"]; // should be `any` | ||
>OmitsKey2 : any | ||
|
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,10 @@ | ||
// #36981 | ||
type AnyRecord = Record<string, any>; | ||
interface ExtendsAny extends AnyRecord { | ||
myKey1: string; | ||
myKey2: string; | ||
} | ||
|
||
type OmitsKey = Omit<ExtendsAny, "myKey2">; | ||
type OmitsKey1 = OmitsKey["myKey1"]; // should be `string` | ||
type OmitsKey2 = OmitsKey["myKey2"]; // should be `any` |
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.
Without this change and the bit below, you couldn't cast between an
Omit
of something and that something. That mapped types withnameType
fields currently have no generic relations is a place we should probably improve upon anyway, however this is the minimal change required to get that comparable relation to work as expected.