Skip to content

Wrong inference from function return argument #13118

Closed
@AlexGalays

Description

@AlexGalays

TypeScript Version: 2.2.0-dev.20161221

Code

type SomeParams<A> = { a: A, enter: (a: A) => void }

function canYouInferThis<A>(fn: () => SomeParams<A>): { aa: A } {
  return { aa: fn().a }
}

const result = canYouInferThis(() => ({ a: { bla: 33 }, enter: a => undefined }))
result.aa.bla // Doesn't compile

Expected behavior:
The A parameter should be inferred to be { bla: number }. It seems completely unambiguous to me.
Failing that, I would expect a warning about ambiguous inferred types.

Actual behavior:
The type of A is silently inferred to be {}

Metadata

Metadata

Assignees

Labels

BugA bug in TypeScript

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions