Skip to content
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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Narrow doesn't work on this parameters #260

Open
DetachHead opened this issue Oct 16, 2021 · 0 comments
Open

Narrow doesn't work on this parameters #260

DetachHead opened this issue Oct 16, 2021 · 0 comments

Comments

@DetachHead
Copy link

DetachHead commented Oct 16, 2021

馃悶 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 microsoft/TypeScript#44268 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant