-
Notifications
You must be signed in to change notification settings - Fork 13.2k
Accept Iterable|ArrayLike union in Array.from, add tests #20467
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
DanielRosenwasser
merged 1 commit into
microsoft:master
from
Jessidhia:array-from-union-fix
Dec 8, 2017
Merged
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
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,46 @@ | ||
| tests/cases/compiler/arrayFrom.ts(19,7): error TS2322: Type 'A[]' is not assignable to type 'B[]'. | ||
| Type 'A' is not assignable to type 'B'. | ||
| Property 'b' is missing in type 'A'. | ||
| tests/cases/compiler/arrayFrom.ts(22,7): error TS2322: Type 'A[]' is not assignable to type 'B[]'. | ||
|
|
||
|
|
||
| ==== tests/cases/compiler/arrayFrom.ts (2 errors) ==== | ||
| // Tests fix for #20432, ensures Array.from accepts all valid inputs | ||
| // Also tests for #19682 | ||
|
|
||
| interface A { | ||
| a: string; | ||
| } | ||
|
|
||
| interface B { | ||
| b: string; | ||
| } | ||
|
|
||
| const inputA: A[] = []; | ||
| const inputB: B[] = []; | ||
| const inputALike: ArrayLike<A> = { length: 0 }; | ||
| const inputARand = getEither(inputA, inputALike); | ||
|
|
||
| const result1: A[] = Array.from(inputA); | ||
| const result2: A[] = Array.from(inputA.values()); | ||
| const result3: B[] = Array.from(inputA.values()); // expect error | ||
| ~~~~~~~ | ||
| !!! error TS2322: Type 'A[]' is not assignable to type 'B[]'. | ||
| !!! error TS2322: Type 'A' is not assignable to type 'B'. | ||
| !!! error TS2322: Property 'b' is missing in type 'A'. | ||
| const result4: A[] = Array.from(inputB, ({ b }): A => ({ a: b })); | ||
| const result5: A[] = Array.from(inputALike); | ||
| const result6: B[] = Array.from(inputALike); // expect error | ||
| ~~~~~~~ | ||
| !!! error TS2322: Type 'A[]' is not assignable to type 'B[]'. | ||
| const result7: B[] = Array.from(inputALike, ({ a }): B => ({ b: a })); | ||
| const result8: A[] = Array.from(inputARand); | ||
| const result9: B[] = Array.from(inputARand, ({ a }): B => ({ b: a })); | ||
|
|
||
| // if this is written inline, the compiler seems to infer | ||
| // the ?: as always taking the false branch, narrowing to ArrayLike<T>, | ||
| // even when the type is written as : Iterable<T>|ArrayLike<T> | ||
| function getEither<T> (in1: Iterable<T>, in2: ArrayLike<T>) { | ||
| return Math.random() > 0.5 ? in1 : in2; | ||
| } | ||
|
|
||
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,66 @@ | ||
| //// [arrayFrom.ts] | ||
| // Tests fix for #20432, ensures Array.from accepts all valid inputs | ||
| // Also tests for #19682 | ||
|
|
||
| interface A { | ||
| a: string; | ||
| } | ||
|
|
||
| interface B { | ||
| b: string; | ||
| } | ||
|
|
||
| const inputA: A[] = []; | ||
| const inputB: B[] = []; | ||
| const inputALike: ArrayLike<A> = { length: 0 }; | ||
| const inputARand = getEither(inputA, inputALike); | ||
|
|
||
| const result1: A[] = Array.from(inputA); | ||
| const result2: A[] = Array.from(inputA.values()); | ||
| const result3: B[] = Array.from(inputA.values()); // expect error | ||
| const result4: A[] = Array.from(inputB, ({ b }): A => ({ a: b })); | ||
| const result5: A[] = Array.from(inputALike); | ||
| const result6: B[] = Array.from(inputALike); // expect error | ||
| const result7: B[] = Array.from(inputALike, ({ a }): B => ({ b: a })); | ||
| const result8: A[] = Array.from(inputARand); | ||
| const result9: B[] = Array.from(inputARand, ({ a }): B => ({ b: a })); | ||
|
|
||
| // if this is written inline, the compiler seems to infer | ||
| // the ?: as always taking the false branch, narrowing to ArrayLike<T>, | ||
| // even when the type is written as : Iterable<T>|ArrayLike<T> | ||
| function getEither<T> (in1: Iterable<T>, in2: ArrayLike<T>) { | ||
| return Math.random() > 0.5 ? in1 : in2; | ||
| } | ||
|
|
||
|
|
||
| //// [arrayFrom.js] | ||
| // Tests fix for #20432, ensures Array.from accepts all valid inputs | ||
| // Also tests for #19682 | ||
| var inputA = []; | ||
| var inputB = []; | ||
| var inputALike = { length: 0 }; | ||
| var inputARand = getEither(inputA, inputALike); | ||
| var result1 = Array.from(inputA); | ||
| var result2 = Array.from(inputA.values()); | ||
| var result3 = Array.from(inputA.values()); // expect error | ||
| var result4 = Array.from(inputB, function (_a) { | ||
| var b = _a.b; | ||
| return ({ a: b }); | ||
| }); | ||
| var result5 = Array.from(inputALike); | ||
| var result6 = Array.from(inputALike); // expect error | ||
| var result7 = Array.from(inputALike, function (_a) { | ||
| var a = _a.a; | ||
| return ({ b: a }); | ||
| }); | ||
| var result8 = Array.from(inputARand); | ||
| var result9 = Array.from(inputARand, function (_a) { | ||
| var a = _a.a; | ||
| return ({ b: a }); | ||
| }); | ||
| // if this is written inline, the compiler seems to infer | ||
| // the ?: as always taking the false branch, narrowing to ArrayLike<T>, | ||
| // even when the type is written as : Iterable<T>|ArrayLike<T> | ||
| function getEither(in1, in2) { | ||
| return Math.random() > 0.5 ? in1 : in2; | ||
| } |
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,147 @@ | ||
| === tests/cases/compiler/arrayFrom.ts === | ||
| // Tests fix for #20432, ensures Array.from accepts all valid inputs | ||
| // Also tests for #19682 | ||
|
|
||
| interface A { | ||
| >A : Symbol(A, Decl(arrayFrom.ts, 0, 0)) | ||
|
|
||
| a: string; | ||
| >a : Symbol(A.a, Decl(arrayFrom.ts, 3, 13)) | ||
| } | ||
|
|
||
| interface B { | ||
| >B : Symbol(B, Decl(arrayFrom.ts, 5, 1)) | ||
|
|
||
| b: string; | ||
| >b : Symbol(B.b, Decl(arrayFrom.ts, 7, 13)) | ||
| } | ||
|
|
||
| const inputA: A[] = []; | ||
| >inputA : Symbol(inputA, Decl(arrayFrom.ts, 11, 5)) | ||
| >A : Symbol(A, Decl(arrayFrom.ts, 0, 0)) | ||
|
|
||
| const inputB: B[] = []; | ||
| >inputB : Symbol(inputB, Decl(arrayFrom.ts, 12, 5)) | ||
| >B : Symbol(B, Decl(arrayFrom.ts, 5, 1)) | ||
|
|
||
| const inputALike: ArrayLike<A> = { length: 0 }; | ||
| >inputALike : Symbol(inputALike, Decl(arrayFrom.ts, 13, 5)) | ||
| >ArrayLike : Symbol(ArrayLike, Decl(lib.es5.d.ts, --, --)) | ||
| >A : Symbol(A, Decl(arrayFrom.ts, 0, 0)) | ||
| >length : Symbol(length, Decl(arrayFrom.ts, 13, 34)) | ||
|
|
||
| const inputARand = getEither(inputA, inputALike); | ||
| >inputARand : Symbol(inputARand, Decl(arrayFrom.ts, 14, 5)) | ||
| >getEither : Symbol(getEither, Decl(arrayFrom.ts, 24, 70)) | ||
| >inputA : Symbol(inputA, Decl(arrayFrom.ts, 11, 5)) | ||
| >inputALike : Symbol(inputALike, Decl(arrayFrom.ts, 13, 5)) | ||
|
|
||
| const result1: A[] = Array.from(inputA); | ||
| >result1 : Symbol(result1, Decl(arrayFrom.ts, 16, 5)) | ||
| >A : Symbol(A, Decl(arrayFrom.ts, 0, 0)) | ||
| >Array.from : Symbol(ArrayConstructor.from, Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.core.d.ts, --, --), Decl(lib.es2015.core.d.ts, --, --)) | ||
| >Array : Symbol(Array, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.core.d.ts, --, --)) | ||
| >from : Symbol(ArrayConstructor.from, Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.core.d.ts, --, --), Decl(lib.es2015.core.d.ts, --, --)) | ||
| >inputA : Symbol(inputA, Decl(arrayFrom.ts, 11, 5)) | ||
|
|
||
| const result2: A[] = Array.from(inputA.values()); | ||
| >result2 : Symbol(result2, Decl(arrayFrom.ts, 17, 5)) | ||
| >A : Symbol(A, Decl(arrayFrom.ts, 0, 0)) | ||
| >Array.from : Symbol(ArrayConstructor.from, Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.core.d.ts, --, --), Decl(lib.es2015.core.d.ts, --, --)) | ||
| >Array : Symbol(Array, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.core.d.ts, --, --)) | ||
| >from : Symbol(ArrayConstructor.from, Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.core.d.ts, --, --), Decl(lib.es2015.core.d.ts, --, --)) | ||
| >inputA.values : Symbol(Array.values, Decl(lib.es2015.iterable.d.ts, --, --)) | ||
| >inputA : Symbol(inputA, Decl(arrayFrom.ts, 11, 5)) | ||
| >values : Symbol(Array.values, Decl(lib.es2015.iterable.d.ts, --, --)) | ||
|
|
||
| const result3: B[] = Array.from(inputA.values()); // expect error | ||
| >result3 : Symbol(result3, Decl(arrayFrom.ts, 18, 5)) | ||
| >B : Symbol(B, Decl(arrayFrom.ts, 5, 1)) | ||
| >Array.from : Symbol(ArrayConstructor.from, Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.core.d.ts, --, --), Decl(lib.es2015.core.d.ts, --, --)) | ||
| >Array : Symbol(Array, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.core.d.ts, --, --)) | ||
| >from : Symbol(ArrayConstructor.from, Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.core.d.ts, --, --), Decl(lib.es2015.core.d.ts, --, --)) | ||
| >inputA.values : Symbol(Array.values, Decl(lib.es2015.iterable.d.ts, --, --)) | ||
| >inputA : Symbol(inputA, Decl(arrayFrom.ts, 11, 5)) | ||
| >values : Symbol(Array.values, Decl(lib.es2015.iterable.d.ts, --, --)) | ||
|
|
||
| const result4: A[] = Array.from(inputB, ({ b }): A => ({ a: b })); | ||
| >result4 : Symbol(result4, Decl(arrayFrom.ts, 19, 5)) | ||
| >A : Symbol(A, Decl(arrayFrom.ts, 0, 0)) | ||
| >Array.from : Symbol(ArrayConstructor.from, Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.core.d.ts, --, --), Decl(lib.es2015.core.d.ts, --, --)) | ||
| >Array : Symbol(Array, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.core.d.ts, --, --)) | ||
| >from : Symbol(ArrayConstructor.from, Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.core.d.ts, --, --), Decl(lib.es2015.core.d.ts, --, --)) | ||
| >inputB : Symbol(inputB, Decl(arrayFrom.ts, 12, 5)) | ||
| >b : Symbol(b, Decl(arrayFrom.ts, 19, 42)) | ||
| >A : Symbol(A, Decl(arrayFrom.ts, 0, 0)) | ||
| >a : Symbol(a, Decl(arrayFrom.ts, 19, 56)) | ||
| >b : Symbol(b, Decl(arrayFrom.ts, 19, 42)) | ||
|
|
||
| const result5: A[] = Array.from(inputALike); | ||
| >result5 : Symbol(result5, Decl(arrayFrom.ts, 20, 5)) | ||
| >A : Symbol(A, Decl(arrayFrom.ts, 0, 0)) | ||
| >Array.from : Symbol(ArrayConstructor.from, Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.core.d.ts, --, --), Decl(lib.es2015.core.d.ts, --, --)) | ||
| >Array : Symbol(Array, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.core.d.ts, --, --)) | ||
| >from : Symbol(ArrayConstructor.from, Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.core.d.ts, --, --), Decl(lib.es2015.core.d.ts, --, --)) | ||
| >inputALike : Symbol(inputALike, Decl(arrayFrom.ts, 13, 5)) | ||
|
|
||
| const result6: B[] = Array.from(inputALike); // expect error | ||
| >result6 : Symbol(result6, Decl(arrayFrom.ts, 21, 5)) | ||
| >B : Symbol(B, Decl(arrayFrom.ts, 5, 1)) | ||
| >Array.from : Symbol(ArrayConstructor.from, Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.core.d.ts, --, --), Decl(lib.es2015.core.d.ts, --, --)) | ||
| >Array : Symbol(Array, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.core.d.ts, --, --)) | ||
| >from : Symbol(ArrayConstructor.from, Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.core.d.ts, --, --), Decl(lib.es2015.core.d.ts, --, --)) | ||
| >inputALike : Symbol(inputALike, Decl(arrayFrom.ts, 13, 5)) | ||
|
|
||
| const result7: B[] = Array.from(inputALike, ({ a }): B => ({ b: a })); | ||
| >result7 : Symbol(result7, Decl(arrayFrom.ts, 22, 5)) | ||
| >B : Symbol(B, Decl(arrayFrom.ts, 5, 1)) | ||
| >Array.from : Symbol(ArrayConstructor.from, Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.core.d.ts, --, --), Decl(lib.es2015.core.d.ts, --, --)) | ||
| >Array : Symbol(Array, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.core.d.ts, --, --)) | ||
| >from : Symbol(ArrayConstructor.from, Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.core.d.ts, --, --), Decl(lib.es2015.core.d.ts, --, --)) | ||
| >inputALike : Symbol(inputALike, Decl(arrayFrom.ts, 13, 5)) | ||
| >a : Symbol(a, Decl(arrayFrom.ts, 22, 46)) | ||
| >B : Symbol(B, Decl(arrayFrom.ts, 5, 1)) | ||
| >b : Symbol(b, Decl(arrayFrom.ts, 22, 60)) | ||
| >a : Symbol(a, Decl(arrayFrom.ts, 22, 46)) | ||
|
|
||
| const result8: A[] = Array.from(inputARand); | ||
| >result8 : Symbol(result8, Decl(arrayFrom.ts, 23, 5)) | ||
| >A : Symbol(A, Decl(arrayFrom.ts, 0, 0)) | ||
| >Array.from : Symbol(ArrayConstructor.from, Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.core.d.ts, --, --), Decl(lib.es2015.core.d.ts, --, --)) | ||
| >Array : Symbol(Array, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.core.d.ts, --, --)) | ||
| >from : Symbol(ArrayConstructor.from, Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.core.d.ts, --, --), Decl(lib.es2015.core.d.ts, --, --)) | ||
| >inputARand : Symbol(inputARand, Decl(arrayFrom.ts, 14, 5)) | ||
|
|
||
| const result9: B[] = Array.from(inputARand, ({ a }): B => ({ b: a })); | ||
| >result9 : Symbol(result9, Decl(arrayFrom.ts, 24, 5)) | ||
| >B : Symbol(B, Decl(arrayFrom.ts, 5, 1)) | ||
| >Array.from : Symbol(ArrayConstructor.from, Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.core.d.ts, --, --), Decl(lib.es2015.core.d.ts, --, --)) | ||
| >Array : Symbol(Array, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.core.d.ts, --, --)) | ||
| >from : Symbol(ArrayConstructor.from, Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.core.d.ts, --, --), Decl(lib.es2015.core.d.ts, --, --)) | ||
| >inputARand : Symbol(inputARand, Decl(arrayFrom.ts, 14, 5)) | ||
| >a : Symbol(a, Decl(arrayFrom.ts, 24, 46)) | ||
| >B : Symbol(B, Decl(arrayFrom.ts, 5, 1)) | ||
| >b : Symbol(b, Decl(arrayFrom.ts, 24, 60)) | ||
| >a : Symbol(a, Decl(arrayFrom.ts, 24, 46)) | ||
|
|
||
| // if this is written inline, the compiler seems to infer | ||
| // the ?: as always taking the false branch, narrowing to ArrayLike<T>, | ||
| // even when the type is written as : Iterable<T>|ArrayLike<T> | ||
| function getEither<T> (in1: Iterable<T>, in2: ArrayLike<T>) { | ||
| >getEither : Symbol(getEither, Decl(arrayFrom.ts, 24, 70)) | ||
| >T : Symbol(T, Decl(arrayFrom.ts, 29, 19)) | ||
| >in1 : Symbol(in1, Decl(arrayFrom.ts, 29, 23)) | ||
| >Iterable : Symbol(Iterable, Decl(lib.es2015.iterable.d.ts, --, --)) | ||
| >T : Symbol(T, Decl(arrayFrom.ts, 29, 19)) | ||
| >in2 : Symbol(in2, Decl(arrayFrom.ts, 29, 40)) | ||
| >ArrayLike : Symbol(ArrayLike, Decl(lib.es5.d.ts, --, --)) | ||
| >T : Symbol(T, Decl(arrayFrom.ts, 29, 19)) | ||
|
|
||
| return Math.random() > 0.5 ? in1 : in2; | ||
| >Math.random : Symbol(Math.random, Decl(lib.es5.d.ts, --, --)) | ||
| >Math : Symbol(Math, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --), Decl(lib.es2015.core.d.ts, --, --)) | ||
| >random : Symbol(Math.random, Decl(lib.es5.d.ts, --, --)) | ||
| >in1 : Symbol(in1, Decl(arrayFrom.ts, 29, 23)) | ||
| >in2 : Symbol(in2, Decl(arrayFrom.ts, 29, 40)) | ||
| } | ||
|
|
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.
This would not error out if
mapfnwas optional instead of an extra parameter in an overload