ts-toolbelt
ts-toolbelt copied to clipboard
`Narrow` doesn't work on `this` parameters
🐞 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>
}
}
see https://github.com/microsoft/TypeScript/issues/44268#issuecomment-944037476