镜像站点 · 本页由第三方 GitHub 只读镜像提供,非 GitHub 官方站点,不接受任何登录或凭据输入。前往 github.com
Skip to content

Callback in mapped type implicitly has 'any' type #23429

Description

TypeScript Version: 2.9.0-dev.20180414

Code

declare function watch<T>(obj: T, propertyChangedCallbacks: { [K in keyof T]: (obj: T) => void }): void;
watch({ x: 0 }, {
    x: obj => {},
});

Expected behavior:

obj is { x: number }.

Actual behavior:

src/a.ts(3,8): error TS7006: Parameter 'obj' implicitly has an 'any' type.

Activity

  1. bcherny commented on Apr 22, 2018

    @bcherny

    This is happening on 2.8.1 too:

    type Events = {
      ready: () => void
      error: (e: Error) => void
      reconnecting: (params: { attempt: number, delay: number}) => void
    }
    
    type RedisClient = {
      on<E extends keyof Events>(event: E, f: Events[E]): void
    }
    
    let c: RedisClient
    
    c.on('ready', () => 4)               // BAD - arity is propagated, return type is any
    c.on('error', e => 4)                // BAD - e is any
    c.on('reconnecting', p => p.attempt) // BAD - p is any

    Playground

  2. russelldavis commented on Jun 5, 2023

    @russelldavis
    Contributor

    I just checked this in the TS playground, looks like this has been fixed (since v3.5.1)

  3. RyanCavanaugh commented on Jul 23, 2025

    @RyanCavanaugh
    Member

    Confirmed

  4. locked as resolved and limited conversation to collaborators on Jan 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugA bug in TypeScript

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions