Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Incorrect inference for function expression with type annotation and generic #16293

Copy link
Copy link
@OliverJAsh

Description

@OliverJAsh
Issue body actions

#TypeScript Version: 2.3.4

Code

// I can conveniently annotate a function express with a type
// This is good because the types don't litter the implementation

{
    type add = (a: number) => (b: number) => number;
    const add: add = a => b => a + b; // a and b are type number
}

// However, if I try to do the same where the function type has a generic…

{
    type fn = <A>(a: A) => A;
    const fn: fn = a => a; // a is inferred as any, but expected A
}

Is there any way to annotate the function expression fn with the type fn without breaking inference for the parameters?

Reactions are currently unavailable

Metadata

Metadata

Assignees

Labels

BugA bug in TypeScriptA bug in TypeScriptFixedA PR has been merged for this issueA PR has been merged for this issue

Type

No type
No fields configured for issues without a type.

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions

    Morty Proxy This is a proxified and sanitized view of the page, visit original site.