Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Overload selection differs for mapped types vs interfaces #25378

Closed
OliverJAsh opened this issue Jul 2, 2018 · 2 comments
Closed

Overload selection differs for mapped types vs interfaces #25378

OliverJAsh opened this issue Jul 2, 2018 · 2 comments
Labels
Duplicate An existing issue was already created

Comments

@OliverJAsh
Copy link
Contributor

OliverJAsh commented Jul 2, 2018

TypeScript Version: 2.9.1

Search Terms: overload mapped types interface

Code

interface LoDashStatic {
  mapValues<T, TResult>(
      obj: { [index: string]: T },
      callback: (t: T) => TResult,
  ): { [index: string]: TResult };
  mapValues<T extends object, TResult>(
      obj: T,
      callback: (t: T[keyof T]) => TResult,
  ): { [P in keyof T]: TResult };
}

declare const _: LoDashStatic;

interface AbcObjectInterface {
  a: number;
  b: string;
  c: boolean;
}
type AbcObjectRecord = Record<"a" | "b" | "c", string>;

declare const abcObjectRecord: AbcObjectRecord;
declare const abcObjectInterface: AbcObjectInterface;

// Expected return type to be `{ a: number; b: number; c: string }` and got :-)
// The second overload is used, as expected.
_.mapValues(abcObjectInterface, (v) => 1);

// Expected return type to be `Record<"a" | "b" | "c", number>` but got `{ [index: string]: number }` :-(
// The first overload is used, unexpectedly.
_.mapValues(abcObjectRecord, (v) => 1);

Related Issues: DefinitelyTyped/DefinitelyTyped#26983 (comment)

@mhegazy
Copy link
Contributor

mhegazy commented Jul 2, 2018

Duplicate of #15300

@mhegazy mhegazy marked this as a duplicate of #15300 Jul 2, 2018
@mhegazy mhegazy added the Duplicate An existing issue was already created label Jul 2, 2018
@OliverJAsh
Copy link
Contributor Author

Ta!

@OliverJAsh OliverJAsh reopened this Jul 2, 2018
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
Duplicate An existing issue was already created
Projects
None yet
Development

No branches or pull requests

2 participants