-
Notifications
You must be signed in to change notification settings - Fork 13.4k
Infer optional types for IIFE parameters with missing arguments #13358
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 all commits
Commits
Show all changes
3 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
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
110 changes: 110 additions & 0 deletions
110
tests/baselines/reference/contextuallyTypedIifeStrict.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,110 @@ | ||
| //// [contextuallyTypedIifeStrict.ts] | ||
| // arrow | ||
| (jake => { })("build"); | ||
| // function expression | ||
| (function (cats) { })("lol"); | ||
| // Lots of Irritating Superfluous Parentheses | ||
| (function (x) { } ("!")); | ||
| ((((function (y) { }))))("-"); | ||
| // multiple arguments | ||
| ((a, b, c) => { })("foo", 101, false); | ||
| // default parameters | ||
| ((m = 10) => m + 1)(12); | ||
| ((n = 10) => n + 1)(); | ||
| // optional parameters | ||
| ((j?) => j + 1)(12); | ||
| ((k?) => k + 1)(); | ||
| ((l, o?) => l + o)(12); // o should be any | ||
| // rest parameters | ||
| ((...numbers) => numbers.every(n => n > 0))(5,6,7); | ||
| ((...mixed) => mixed.every(n => !!n))(5,'oops','oh no'); | ||
| ((...noNumbers) => noNumbers.some(n => n > 0))(); | ||
| ((first, ...rest) => first ? [] : rest.map(n => n > 0))(8,9,10); | ||
| // destructuring parameters (with defaults too!) | ||
| (({ q }) => q)({ q : 13 }); | ||
| (({ p = 14 }) => p)({ p : 15 }); | ||
| (({ r = 17 } = { r: 18 }) => r)({r : 19}); | ||
| (({ u = 22 } = { u: 23 }) => u)(); | ||
| // contextually typed parameters. | ||
| let twelve = (f => f(12))(i => i); | ||
| let eleven = (o => o.a(11))({ a: function(n) { return n; } }); | ||
| // missing arguments | ||
| (function(x, undefined) { return x; })(42); | ||
| ((x, y, z) => 42)(); | ||
|
|
||
|
|
||
| //// [contextuallyTypedIifeStrict.js] | ||
| // arrow | ||
| (function (jake) { })("build"); | ||
| // function expression | ||
| (function (cats) { })("lol"); | ||
| // Lots of Irritating Superfluous Parentheses | ||
| (function (x) { }("!")); | ||
| ((((function (y) { }))))("-"); | ||
| // multiple arguments | ||
| (function (a, b, c) { })("foo", 101, false); | ||
| // default parameters | ||
| (function (m) { | ||
| if (m === void 0) { m = 10; } | ||
| return m + 1; | ||
| })(12); | ||
| (function (n) { | ||
| if (n === void 0) { n = 10; } | ||
| return n + 1; | ||
| })(); | ||
| // optional parameters | ||
| (function (j) { return j + 1; })(12); | ||
| (function (k) { return k + 1; })(); | ||
| (function (l, o) { return l + o; })(12); // o should be any | ||
| // rest parameters | ||
| (function () { | ||
| var numbers = []; | ||
| for (var _i = 0; _i < arguments.length; _i++) { | ||
| numbers[_i] = arguments[_i]; | ||
| } | ||
| return numbers.every(function (n) { return n > 0; }); | ||
| })(5, 6, 7); | ||
| (function () { | ||
| var mixed = []; | ||
| for (var _i = 0; _i < arguments.length; _i++) { | ||
| mixed[_i] = arguments[_i]; | ||
| } | ||
| return mixed.every(function (n) { return !!n; }); | ||
| })(5, 'oops', 'oh no'); | ||
| (function () { | ||
| var noNumbers = []; | ||
| for (var _i = 0; _i < arguments.length; _i++) { | ||
| noNumbers[_i] = arguments[_i]; | ||
| } | ||
| return noNumbers.some(function (n) { return n > 0; }); | ||
| })(); | ||
| (function (first) { | ||
| var rest = []; | ||
| for (var _i = 1; _i < arguments.length; _i++) { | ||
| rest[_i - 1] = arguments[_i]; | ||
| } | ||
| return first ? [] : rest.map(function (n) { return n > 0; }); | ||
| })(8, 9, 10); | ||
| // destructuring parameters (with defaults too!) | ||
| (function (_a) { | ||
| var q = _a.q; | ||
| return q; | ||
| })({ q: 13 }); | ||
| (function (_a) { | ||
| var _b = _a.p, p = _b === void 0 ? 14 : _b; | ||
| return p; | ||
| })({ p: 15 }); | ||
| (function (_a) { | ||
| var _b = (_a === void 0 ? { r: 18 } : _a).r, r = _b === void 0 ? 17 : _b; | ||
| return r; | ||
| })({ r: 19 }); | ||
| (function (_a) { | ||
| var _b = (_a === void 0 ? { u: 23 } : _a).u, u = _b === void 0 ? 22 : _b; | ||
| return u; | ||
| })(); | ||
| // contextually typed parameters. | ||
| var twelve = (function (f) { return f(12); })(function (i) { return i; }); | ||
| var eleven = (function (o) { return o.a(11); })({ a: function (n) { return n; } }); | ||
| // missing arguments | ||
| (function (x, undefined) { return x; })(42); | ||
| (function (x, y, z) { return 42; })(); |
132 changes: 132 additions & 0 deletions
132
tests/baselines/reference/contextuallyTypedIifeStrict.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,132 @@ | ||
| === tests/cases/conformance/expressions/functions/contextuallyTypedIifeStrict.ts === | ||
| // arrow | ||
| (jake => { })("build"); | ||
| >jake : Symbol(jake, Decl(contextuallyTypedIifeStrict.ts, 1, 1)) | ||
|
|
||
| // function expression | ||
| (function (cats) { })("lol"); | ||
| >cats : Symbol(cats, Decl(contextuallyTypedIifeStrict.ts, 3, 11)) | ||
|
|
||
| // Lots of Irritating Superfluous Parentheses | ||
| (function (x) { } ("!")); | ||
| >x : Symbol(x, Decl(contextuallyTypedIifeStrict.ts, 5, 11)) | ||
|
|
||
| ((((function (y) { }))))("-"); | ||
| >y : Symbol(y, Decl(contextuallyTypedIifeStrict.ts, 6, 14)) | ||
|
|
||
| // multiple arguments | ||
| ((a, b, c) => { })("foo", 101, false); | ||
| >a : Symbol(a, Decl(contextuallyTypedIifeStrict.ts, 8, 2)) | ||
| >b : Symbol(b, Decl(contextuallyTypedIifeStrict.ts, 8, 4)) | ||
| >c : Symbol(c, Decl(contextuallyTypedIifeStrict.ts, 8, 7)) | ||
|
|
||
| // default parameters | ||
| ((m = 10) => m + 1)(12); | ||
| >m : Symbol(m, Decl(contextuallyTypedIifeStrict.ts, 10, 2)) | ||
| >m : Symbol(m, Decl(contextuallyTypedIifeStrict.ts, 10, 2)) | ||
|
|
||
| ((n = 10) => n + 1)(); | ||
| >n : Symbol(n, Decl(contextuallyTypedIifeStrict.ts, 11, 2)) | ||
| >n : Symbol(n, Decl(contextuallyTypedIifeStrict.ts, 11, 2)) | ||
|
|
||
| // optional parameters | ||
| ((j?) => j + 1)(12); | ||
| >j : Symbol(j, Decl(contextuallyTypedIifeStrict.ts, 13, 2)) | ||
| >j : Symbol(j, Decl(contextuallyTypedIifeStrict.ts, 13, 2)) | ||
|
|
||
| ((k?) => k + 1)(); | ||
| >k : Symbol(k, Decl(contextuallyTypedIifeStrict.ts, 14, 2)) | ||
| >k : Symbol(k, Decl(contextuallyTypedIifeStrict.ts, 14, 2)) | ||
|
|
||
| ((l, o?) => l + o)(12); // o should be any | ||
| >l : Symbol(l, Decl(contextuallyTypedIifeStrict.ts, 15, 2)) | ||
| >o : Symbol(o, Decl(contextuallyTypedIifeStrict.ts, 15, 4)) | ||
| >l : Symbol(l, Decl(contextuallyTypedIifeStrict.ts, 15, 2)) | ||
| >o : Symbol(o, Decl(contextuallyTypedIifeStrict.ts, 15, 4)) | ||
|
|
||
| // rest parameters | ||
| ((...numbers) => numbers.every(n => n > 0))(5,6,7); | ||
| >numbers : Symbol(numbers, Decl(contextuallyTypedIifeStrict.ts, 17, 2)) | ||
| >numbers.every : Symbol(Array.every, Decl(lib.d.ts, --, --)) | ||
| >numbers : Symbol(numbers, Decl(contextuallyTypedIifeStrict.ts, 17, 2)) | ||
| >every : Symbol(Array.every, Decl(lib.d.ts, --, --)) | ||
| >n : Symbol(n, Decl(contextuallyTypedIifeStrict.ts, 17, 31)) | ||
| >n : Symbol(n, Decl(contextuallyTypedIifeStrict.ts, 17, 31)) | ||
|
|
||
| ((...mixed) => mixed.every(n => !!n))(5,'oops','oh no'); | ||
| >mixed : Symbol(mixed, Decl(contextuallyTypedIifeStrict.ts, 18, 2)) | ||
| >mixed.every : Symbol(Array.every, Decl(lib.d.ts, --, --)) | ||
| >mixed : Symbol(mixed, Decl(contextuallyTypedIifeStrict.ts, 18, 2)) | ||
| >every : Symbol(Array.every, Decl(lib.d.ts, --, --)) | ||
| >n : Symbol(n, Decl(contextuallyTypedIifeStrict.ts, 18, 27)) | ||
| >n : Symbol(n, Decl(contextuallyTypedIifeStrict.ts, 18, 27)) | ||
|
|
||
| ((...noNumbers) => noNumbers.some(n => n > 0))(); | ||
| >noNumbers : Symbol(noNumbers, Decl(contextuallyTypedIifeStrict.ts, 19, 2)) | ||
| >noNumbers.some : Symbol(Array.some, Decl(lib.d.ts, --, --)) | ||
| >noNumbers : Symbol(noNumbers, Decl(contextuallyTypedIifeStrict.ts, 19, 2)) | ||
| >some : Symbol(Array.some, Decl(lib.d.ts, --, --)) | ||
| >n : Symbol(n, Decl(contextuallyTypedIifeStrict.ts, 19, 34)) | ||
| >n : Symbol(n, Decl(contextuallyTypedIifeStrict.ts, 19, 34)) | ||
|
|
||
| ((first, ...rest) => first ? [] : rest.map(n => n > 0))(8,9,10); | ||
| >first : Symbol(first, Decl(contextuallyTypedIifeStrict.ts, 20, 2)) | ||
| >rest : Symbol(rest, Decl(contextuallyTypedIifeStrict.ts, 20, 8)) | ||
| >first : Symbol(first, Decl(contextuallyTypedIifeStrict.ts, 20, 2)) | ||
| >rest.map : Symbol(Array.map, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --)) | ||
| >rest : Symbol(rest, Decl(contextuallyTypedIifeStrict.ts, 20, 8)) | ||
| >map : Symbol(Array.map, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --)) | ||
| >n : Symbol(n, Decl(contextuallyTypedIifeStrict.ts, 20, 43)) | ||
| >n : Symbol(n, Decl(contextuallyTypedIifeStrict.ts, 20, 43)) | ||
|
|
||
| // destructuring parameters (with defaults too!) | ||
| (({ q }) => q)({ q : 13 }); | ||
| >q : Symbol(q, Decl(contextuallyTypedIifeStrict.ts, 22, 3)) | ||
| >q : Symbol(q, Decl(contextuallyTypedIifeStrict.ts, 22, 3)) | ||
| >q : Symbol(q, Decl(contextuallyTypedIifeStrict.ts, 22, 16)) | ||
|
|
||
| (({ p = 14 }) => p)({ p : 15 }); | ||
| >p : Symbol(p, Decl(contextuallyTypedIifeStrict.ts, 23, 3)) | ||
| >p : Symbol(p, Decl(contextuallyTypedIifeStrict.ts, 23, 3)) | ||
| >p : Symbol(p, Decl(contextuallyTypedIifeStrict.ts, 23, 21)) | ||
|
|
||
| (({ r = 17 } = { r: 18 }) => r)({r : 19}); | ||
| >r : Symbol(r, Decl(contextuallyTypedIifeStrict.ts, 24, 3)) | ||
| >r : Symbol(r, Decl(contextuallyTypedIifeStrict.ts, 24, 16)) | ||
| >r : Symbol(r, Decl(contextuallyTypedIifeStrict.ts, 24, 3)) | ||
| >r : Symbol(r, Decl(contextuallyTypedIifeStrict.ts, 24, 33)) | ||
|
|
||
| (({ u = 22 } = { u: 23 }) => u)(); | ||
| >u : Symbol(u, Decl(contextuallyTypedIifeStrict.ts, 25, 3)) | ||
| >u : Symbol(u, Decl(contextuallyTypedIifeStrict.ts, 25, 16)) | ||
| >u : Symbol(u, Decl(contextuallyTypedIifeStrict.ts, 25, 3)) | ||
|
|
||
| // contextually typed parameters. | ||
| let twelve = (f => f(12))(i => i); | ||
| >twelve : Symbol(twelve, Decl(contextuallyTypedIifeStrict.ts, 27, 3)) | ||
| >f : Symbol(f, Decl(contextuallyTypedIifeStrict.ts, 27, 14)) | ||
| >f : Symbol(f, Decl(contextuallyTypedIifeStrict.ts, 27, 14)) | ||
| >i : Symbol(i, Decl(contextuallyTypedIifeStrict.ts, 27, 26)) | ||
| >i : Symbol(i, Decl(contextuallyTypedIifeStrict.ts, 27, 26)) | ||
|
|
||
| let eleven = (o => o.a(11))({ a: function(n) { return n; } }); | ||
| >eleven : Symbol(eleven, Decl(contextuallyTypedIifeStrict.ts, 28, 3)) | ||
| >o : Symbol(o, Decl(contextuallyTypedIifeStrict.ts, 28, 14)) | ||
| >o.a : Symbol(a, Decl(contextuallyTypedIifeStrict.ts, 28, 29)) | ||
| >o : Symbol(o, Decl(contextuallyTypedIifeStrict.ts, 28, 14)) | ||
| >a : Symbol(a, Decl(contextuallyTypedIifeStrict.ts, 28, 29)) | ||
| >a : Symbol(a, Decl(contextuallyTypedIifeStrict.ts, 28, 29)) | ||
| >n : Symbol(n, Decl(contextuallyTypedIifeStrict.ts, 28, 42)) | ||
| >n : Symbol(n, Decl(contextuallyTypedIifeStrict.ts, 28, 42)) | ||
|
|
||
| // missing arguments | ||
| (function(x, undefined) { return x; })(42); | ||
| >x : Symbol(x, Decl(contextuallyTypedIifeStrict.ts, 30, 10)) | ||
| >undefined : Symbol(undefined, Decl(contextuallyTypedIifeStrict.ts, 30, 12)) | ||
| >x : Symbol(x, Decl(contextuallyTypedIifeStrict.ts, 30, 10)) | ||
|
|
||
| ((x, y, z) => 42)(); | ||
| >x : Symbol(x, Decl(contextuallyTypedIifeStrict.ts, 31, 2)) | ||
| >y : Symbol(y, Decl(contextuallyTypedIifeStrict.ts, 31, 4)) | ||
| >z : Symbol(z, Decl(contextuallyTypedIifeStrict.ts, 31, 7)) | ||
|
|
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.
@sandersn this will need to be covered in your change for initialized parameters.