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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
ghost opened this issue Apr 16, 2018 · 2 comments
Open

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

ghost opened this issue Apr 16, 2018 · 2 comments
Labels
Bug A bug in TypeScript
Milestone

Comments

@ghost
Copy link

ghost commented Apr 16, 2018

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.

@bcherny
Copy link

bcherny commented Apr 22, 2018

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

@russelldavis
Copy link
Contributor

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

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

No branches or pull requests

4 participants