Skip to content

cb: (x: T) => void not assignable to cb: (x: T) => void when it has an overload: "'any' is not assignable to 'never'" #23352

Closed

Description

TypeScript Version: 2.9.0-dev.20180411

Code

declare function provide<T>(cb: (x: T) => void): void;
declare function provide<T>(cb: (x: T[keyof T]) => void): void;

declare function provider<T>(provide: (cb: (x: T) => void) => void): void;
provider(provide);

Expected behavior:

No error.

Actual behavior:

src/a.ts(4,10): error TS2345: Argument of type '{ <T>(cb: (x: T) => void): void; <T>(cb: (x: T[keyof T]) => void): void; }' is not assignable to parameter of type '(cb: (x: never) => void) => void'.
  Types of parameters 'cb' and 'cb' are incompatible.
    Types of parameters 'x' and 'x' are incompatible.
      Type 'any' is not assignable to type 'never'.

Worked in typescript@2.9.0-dev.20180327, broken in typescript@2.9.0-dev.20180328.

Activity

  1. added
    Needs Investigation
    on Jul 17, 2018
  2. added
    Bug
    and removed
    Needs Investigation
    on Oct 12, 2020
  3. weswigham commented on Oct 12, 2020

    @weswigham
    Member

    I've opened a PR with a potential fix for the first, and opened a new issue for the second (since it seems to have a separate root cause) so this issue can just track the first.

  4. added
    Won't Fix
    and removed
    Bug
    on Feb 11, 2022
  5. RyanCavanaugh commented on Feb 11, 2022

    @RyanCavanaugh
    Member

    The fix here seems to have nonzero perf impact and we haven't seen any other reports. Punting for now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

Won't Fix

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions