You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Mapped types doesn't map the key value for methods when mapping over a generic instantiated with an array #58694
v2 has type (callbackfn: (value: boolean, index: number, array: boolean[]) => void, thisArg?: any) => void
🙂 Expected behavior
v2 has type boolean, same as v1
Additional information about the issue
This looks closely related to #27995, but I believe that it is different. My issue is not about the set of keys being mapped, but about some of them not being mapped but just copied as-is from the original type.
changed the title [-]Mapped types doesn't map the key value for methods when mapping over an array[/-][+]Mapped types doesn't map the key value for methods when mapping over a generic instantiated with an array[/+]on May 29, 2024
Btw, my original use case was that I was trying to convert an array type into an array-like (i.e. same type, but without the array methods). I tried something like this but it obviously didn't work:
Activity
nicolo-ribaudo commentedon May 29, 2024
This only happens if I'm mapping over a generic type argument. If I inline it it works properly:
https://www.typescriptlang.org/play/?#code/C4TwDgpgBAggTnAhiA0hEBnAQgV2FgewIBsJEA7ANUWJwgygF4oBvKAbRSgEtyoBrdAQBmsBMgA8GYHF4BzAHwBdAFxQARkVIUoAXwBQ+0sCgA3AExr4SVOmx5CJMlRp0M7AETCCcAKKIAYwALDyUmKBk6AG59AHpYqAA9AH4NLWd9IA
and
https://www.typescriptlang.org/play/?#code/C4TwDgpgBAcg9sAKlAvFAggJ0wQxAHgGdhMBLAOwHMA+AbgChRIoBlHAWwgGkIRCAhAK7B+cOABsIOcgDUc4wREL5E1VFADeUANpcoFKAGtecAGawEiALoAuKACMxk6VAC+9epOBQAbgCY7Nk4ePiERJylZeUVlLFwCYjIqamptACJTOEwAURwAYwALNKt1EkUGAHoKqAA9AH56IA
[-]Mapped types doesn't map the key value for methods when mapping over an array[/-][+]Mapped types doesn't map the key value for methods when mapping over a generic instantiated with an array[/+]jcalz commentedon May 29, 2024
Generic mapped array/tuples are not supposed to map over all the keys. It’s in the TS3.1 release notes. TS is behaving as intended; it’s not a bug.
https://www.typescriptlang.org/docs/handbook/release-notes/typescript-3-1.html#mapped-types-on-tuples-and-arrays
nicolo-ribaudo commentedon May 29, 2024
Then is the bug the behavior I see in #58694 (comment)?
jcalz commentedon May 29, 2024
#27995, yes.
nicolo-ribaudo commentedon May 29, 2024
Oh, closing as a duplicate of #27995 then :)
Btw, my original use case was that I was trying to convert an array type into an array-like (i.e. same type, but without the array methods). I tried something like this but it obviously didn't work:
I then relaized that this is better: