-
Notifications
You must be signed in to change notification settings - Fork 13.1k
Use missingType instead of undefinedType for optional methods under exactOptionalPropertyTypes
#52519
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
Merged
Merged
Use missingType instead of undefinedType for optional methods under exactOptionalPropertyTypes
#52519
Changes from all commits
Commits
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
31 changes: 31 additions & 0 deletions
31
tests/baselines/reference/stripMembersOptionality(exactoptionalpropertytypes=false).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,31 @@ | ||
| === tests/cases/compiler/stripMembersOptionality.ts === | ||
| // repro from #52494 | ||
|
|
||
| declare const someVal: Required<{ | ||
| >someVal : Symbol(someVal, Decl(stripMembersOptionality.ts, 2, 13)) | ||
| >Required : Symbol(Required, Decl(lib.es5.d.ts, --, --)) | ||
|
|
||
| fn?(key: string): string | null; | ||
| >fn : Symbol(fn, Decl(stripMembersOptionality.ts, 2, 33)) | ||
| >key : Symbol(key, Decl(stripMembersOptionality.ts, 3, 8)) | ||
|
|
||
| }>; | ||
| someVal.fn(""); | ||
| >someVal.fn : Symbol(fn, Decl(stripMembersOptionality.ts, 2, 33)) | ||
| >someVal : Symbol(someVal, Decl(stripMembersOptionality.ts, 2, 13)) | ||
| >fn : Symbol(fn, Decl(stripMembersOptionality.ts, 2, 33)) | ||
|
|
||
| declare const someVal2: Required<{ | ||
| >someVal2 : Symbol(someVal2, Decl(stripMembersOptionality.ts, 7, 13)) | ||
| >Required : Symbol(Required, Decl(lib.es5.d.ts, --, --)) | ||
|
|
||
| fn?: (key: string) => string | null; | ||
| >fn : Symbol(fn, Decl(stripMembersOptionality.ts, 7, 34)) | ||
| >key : Symbol(key, Decl(stripMembersOptionality.ts, 8, 10)) | ||
|
|
||
| }>; | ||
| someVal2.fn(""); | ||
| >someVal2.fn : Symbol(fn, Decl(stripMembersOptionality.ts, 7, 34)) | ||
| >someVal2 : Symbol(someVal2, Decl(stripMembersOptionality.ts, 7, 13)) | ||
| >fn : Symbol(fn, Decl(stripMembersOptionality.ts, 7, 34)) | ||
|
|
35 changes: 35 additions & 0 deletions
35
tests/baselines/reference/stripMembersOptionality(exactoptionalpropertytypes=false).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,35 @@ | ||
| === tests/cases/compiler/stripMembersOptionality.ts === | ||
| // repro from #52494 | ||
|
|
||
| declare const someVal: Required<{ | ||
| >someVal : Required<{ fn?(key: string): string | null; }> | ||
|
|
||
| fn?(key: string): string | null; | ||
| >fn : ((key: string) => string | null) | undefined | ||
| >key : string | ||
| >null : null | ||
|
|
||
| }>; | ||
| someVal.fn(""); | ||
| >someVal.fn("") : string | null | ||
| >someVal.fn : (key: string) => string | null | ||
| >someVal : Required<{ fn?(key: string): string | null; }> | ||
| >fn : (key: string) => string | null | ||
| >"" : "" | ||
|
|
||
| declare const someVal2: Required<{ | ||
| >someVal2 : Required<{ fn?: ((key: string) => string | null) | undefined; }> | ||
|
|
||
| fn?: (key: string) => string | null; | ||
| >fn : ((key: string) => string | null) | undefined | ||
| >key : string | ||
| >null : null | ||
|
|
||
| }>; | ||
| someVal2.fn(""); | ||
| >someVal2.fn("") : string | null | ||
| >someVal2.fn : (key: string) => string | null | ||
| >someVal2 : Required<{ fn?: ((key: string) => string | null) | undefined; }> | ||
| >fn : (key: string) => string | null | ||
| >"" : "" | ||
|
|
31 changes: 31 additions & 0 deletions
31
tests/baselines/reference/stripMembersOptionality(exactoptionalpropertytypes=true).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,31 @@ | ||
| === tests/cases/compiler/stripMembersOptionality.ts === | ||
| // repro from #52494 | ||
|
|
||
| declare const someVal: Required<{ | ||
| >someVal : Symbol(someVal, Decl(stripMembersOptionality.ts, 2, 13)) | ||
| >Required : Symbol(Required, Decl(lib.es5.d.ts, --, --)) | ||
|
|
||
| fn?(key: string): string | null; | ||
| >fn : Symbol(fn, Decl(stripMembersOptionality.ts, 2, 33)) | ||
| >key : Symbol(key, Decl(stripMembersOptionality.ts, 3, 8)) | ||
|
|
||
| }>; | ||
| someVal.fn(""); | ||
| >someVal.fn : Symbol(fn, Decl(stripMembersOptionality.ts, 2, 33)) | ||
| >someVal : Symbol(someVal, Decl(stripMembersOptionality.ts, 2, 13)) | ||
| >fn : Symbol(fn, Decl(stripMembersOptionality.ts, 2, 33)) | ||
|
|
||
| declare const someVal2: Required<{ | ||
| >someVal2 : Symbol(someVal2, Decl(stripMembersOptionality.ts, 7, 13)) | ||
| >Required : Symbol(Required, Decl(lib.es5.d.ts, --, --)) | ||
|
|
||
| fn?: (key: string) => string | null; | ||
| >fn : Symbol(fn, Decl(stripMembersOptionality.ts, 7, 34)) | ||
| >key : Symbol(key, Decl(stripMembersOptionality.ts, 8, 10)) | ||
|
|
||
| }>; | ||
| someVal2.fn(""); | ||
| >someVal2.fn : Symbol(fn, Decl(stripMembersOptionality.ts, 7, 34)) | ||
| >someVal2 : Symbol(someVal2, Decl(stripMembersOptionality.ts, 7, 13)) | ||
| >fn : Symbol(fn, Decl(stripMembersOptionality.ts, 7, 34)) | ||
|
|
35 changes: 35 additions & 0 deletions
35
tests/baselines/reference/stripMembersOptionality(exactoptionalpropertytypes=true).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,35 @@ | ||
| === tests/cases/compiler/stripMembersOptionality.ts === | ||
| // repro from #52494 | ||
|
|
||
| declare const someVal: Required<{ | ||
| >someVal : Required<{ fn?(key: string): string | null; }> | ||
|
|
||
| fn?(key: string): string | null; | ||
| >fn : ((key: string) => string | null) | undefined | ||
| >key : string | ||
| >null : null | ||
|
|
||
| }>; | ||
| someVal.fn(""); | ||
| >someVal.fn("") : string | null | ||
| >someVal.fn : (key: string) => string | null | ||
| >someVal : Required<{ fn?(key: string): string | null; }> | ||
| >fn : (key: string) => string | null | ||
| >"" : "" | ||
|
|
||
| declare const someVal2: Required<{ | ||
| >someVal2 : Required<{ fn?: (key: string) => string | null; }> | ||
|
|
||
| fn?: (key: string) => string | null; | ||
| >fn : ((key: string) => string | null) | undefined | ||
| >key : string | ||
| >null : null | ||
|
|
||
| }>; | ||
| someVal2.fn(""); | ||
| >someVal2.fn("") : string | null | ||
| >someVal2.fn : (key: string) => string | null | ||
| >someVal2 : Required<{ fn?: (key: string) => string | null; }> | ||
| >fn : (key: string) => string | null | ||
| >"" : "" | ||
|
|
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,15 @@ | ||
| // @strict: true | ||
| // @exactOptionalPropertyTypes: true, false | ||
| // @noEmit: true | ||
|
|
||
| // repro from #52494 | ||
|
|
||
| declare const someVal: Required<{ | ||
| fn?(key: string): string | null; | ||
| }>; | ||
| someVal.fn(""); | ||
|
|
||
| declare const someVal2: Required<{ | ||
| fn?: (key: string) => string | null; | ||
| }>; | ||
| someVal2.fn(""); |
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.
Uh oh!
There was an error while loading. Please reload this page.
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.
I'm honestly really suspicious of every other call to this function now; I went and made
isPropertyrequired and about half of the callers are actually working with things that are explicitly property types (and so likely need to also pass true).No tests change when I make everyone pass in this parameter, though, which makes me think that we don't have enough coverage of this particular option.
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 option has a default though - did you try passing
trueto all calls of this function?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.
No, I mean I changed it from
isProperty = falsetoisProperty: booleanand then examined all of the places where it error'd.Not that this is directly required for this PR, just something I noticed.
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.
The
missingTypething is only relevant here for withexactOptionalPropertyTypes- and that's not the most popular compiler option. So I definitely wouldn't be surprised if the test suite wouldn't be that comprehensive in this regard.