Skip to content

Argument inference change in 3.4.4 #31297

Closed
@zcregan

Description

@zcregan

TypeScript Version: 3.4.4-dev.20190507

Search Terms: 3.4.4 generic argument inference

Code

function wrap<Self>(
  creator: (self: Self) => Self
) {}

wrap(self => ({
  val: 2,

  func(): number {
    return self.val;
  },
}));

Expected behavior:
Expected to compile without any errors, with the type of self inferred as { val: number, func(): number }. This works as expected from v3.1 -> 3.4.3

Actual behavior:
As of 3.4.4 this no longer works. Looks like self is being inferred as {}. TypeScript emits the following error at return self.val:

9:17 - error TS2339: Property 'val' does not exist on type '{}'.

I tested this with [email protected] and it looks like self is being inferred as unknown. It emits the following error:

9:12 - error TS2571: Object is of type 'unknown'.

Playground Link:
works in older version of TypeScript

Metadata

Metadata

Assignees

Labels

Domain: Type InferenceRelated to type inference performed during signature resolution or `infer` type resolutionWorking as IntendedThe behavior described is the intended behavior; this is not a bug

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions