-
Notifications
You must be signed in to change notification settings - Fork 13.2k
Add undefined to default-initialised parameters #12033
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
Changes from 2 commits
Commits
Show all changes
28 commits
Select commit
Hold shift + click to select a range
995732f
Add undefined to default-valued parameters
sandersn 286845c
Test adding undefined to default-valued parameters
sandersn 00ff0e5
Do not add undefined to parameter properties
sandersn bb9b681
Merge branch 'master' into add-undefined-to-default-valued-parameters
sandersn 96c14de
More tests:default-valued parameter+strictNullChecks
sandersn d62dd29
Merge branch 'master' into add-undefined-to-default-valued-parameters
sandersn caad486
More test cases and notes
sandersn bb6f3ad
Add parameter initialisers to control flow
sandersn f097eaf
More tests of parameter initialiser type
sandersn 8b29e82
Merge branch 'master' into add-undefined-to-default-valued-parameters
sandersn 6046318
Add `| undefined` in .d.ts for initialised params
sandersn 739c083
More tests of initialised parameters adding undefined
sandersn cee708d
Remove undefined when checking patterns in function declarations
sandersn 61c742a
Update tests
sandersn 6543048
Change narrowing rules for parameter initialisers
sandersn 3b1309d
Test parameter initialisation narrowing rules
sandersn e0bf73f
Remove old add-undefined code in getTypeOfParameter
sandersn 156d5a9
Add `| undefined` to all optional properties too
sandersn 8a9ee1a
Merge branch 'master' into add-undefined-to-default-valued-parameters
sandersn e96b17b
Merge branch 'master' into add-undefined-to-default-valued-parameters
sandersn 01a9e4f
isOptionalParameter says unused IIFE arguments are optional
sandersn 3c243db
Remove control flow-based undefined addition
sandersn bb40819
Update tests and baselines
sandersn a235d54
Remove undefined from initialized+annotated parameter type
sandersn 7cf595a
Test removing undefined from initialized, annotated parameters
sandersn 6f7c984
Address PR comments
sandersn 6328e6c
Update baselines
sandersn c2cd4f6
Address PR comments and fix lint
sandersn 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
9 changes: 9 additions & 0 deletions
9
tests/baselines/reference/defaultParameterAddsUndefinedWithStrictNullChecks.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,9 @@ | ||
| //// [defaultParameterAddsUndefinedWithStrictNullChecks.ts] | ||
| function f(addUndefined1 = "J", addUndefined2?: number) { | ||
| } | ||
|
|
||
|
|
||
| //// [defaultParameterAddsUndefinedWithStrictNullChecks.js] | ||
| function f(addUndefined1, addUndefined2) { | ||
| if (addUndefined1 === void 0) { addUndefined1 = "J"; } | ||
| } |
7 changes: 7 additions & 0 deletions
7
tests/baselines/reference/defaultParameterAddsUndefinedWithStrictNullChecks.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,7 @@ | ||
| === tests/cases/compiler/defaultParameterAddsUndefinedWithStrictNullChecks.ts === | ||
| function f(addUndefined1 = "J", addUndefined2?: number) { | ||
| >f : Symbol(f, Decl(defaultParameterAddsUndefinedWithStrictNullChecks.ts, 0, 0)) | ||
| >addUndefined1 : Symbol(addUndefined1, Decl(defaultParameterAddsUndefinedWithStrictNullChecks.ts, 0, 11)) | ||
| >addUndefined2 : Symbol(addUndefined2, Decl(defaultParameterAddsUndefinedWithStrictNullChecks.ts, 0, 31)) | ||
| } | ||
|
|
8 changes: 8 additions & 0 deletions
8
tests/baselines/reference/defaultParameterAddsUndefinedWithStrictNullChecks.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,8 @@ | ||
| === tests/cases/compiler/defaultParameterAddsUndefinedWithStrictNullChecks.ts === | ||
| function f(addUndefined1 = "J", addUndefined2?: number) { | ||
| >f : (addUndefined1?: string | undefined, addUndefined2?: number | undefined) => void | ||
| >addUndefined1 : string | undefined | ||
| >"J" : "J" | ||
| >addUndefined2 : number | undefined | ||
| } | ||
|
|
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
3 changes: 3 additions & 0 deletions
3
tests/cases/compiler/defaultParameterAddsUndefinedWithStrictNullChecks.ts
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,3 @@ | ||
| // @strictNullChecks: true | ||
| function f(addUndefined1 = "J", addUndefined2?: number) { | ||
| } |
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.
This is incorrect -- because there was a non-
undefinedinitializer, the property should not includeundefinedThere 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.
Fixed.