`Narrow` doesn't work on `this` parameters
DetachHead opened this issue Β· comments
DetachHead commented
π Bug Report
Reproduce the bug
declare global {
interface Array<T> {
fn<A>(this: Narrow<A>): A
}
}
// expected type: ['foo', 'bar']
// actual type: string[]
const foo = ['foo', 'bar'].fn()
Expected behavior
type is ['foo', 'bar']
Additional context
i'm trying to improve some of the builtin types using ts-toolbelt, but can only do so using a this
parameter
declare global {
interface ReadonlyArray<T> {
join<Arr extends ReadonlyArray<Literal>, D extends string = ','>(
this: Arr,
delimiter?: D
): Join<Arr, D>
}
interface Array<T> extends ReadonlyArray<T> {
join<Arr extends ReadonlyArray<Literal>, D extends string = ','>(
this: Arr,
delimiter?: D
): Join<Arr, D>
}
}