Let's consider including an extension method to the existing Object
:
declare global {
interface Object {
ext<B>(f: (x: this) => B): B;
}
}
The aim is to apply it as shown below:
"x".ext(x => x.toUpperCase())
//or
(1).ext(x => x + 1)
However, this won't work, as the function's x
parameter is assumed to be Object
.
I expect it to be assumed as "this
" (String
/Number
in these scenarios), the type of .ext()
's receiver.