Skip to content

Type constrain will cause the inferred type to be less specific #28422

@weichensw

Description

@weichensw

TypeScript Version: 3.2.0-dev.20181107

Search Terms:
Type constrain inferred
Code

function test1<P extends any[], R>(
  t: ((...args: P) => R),
): (...args: P) => R {
    return t;
}

function wrap1<T extends (...args: any[]) => any>(resultFn: T): T{
    return resultFn;
}

const test11 = wrap1(test1);

function wrap2<T>(resultFn: T): T{
    return resultFn;
}

const test12 = wrap2(test1);

Expected behavior:
typeof test11 should be the same as typeof test1 as the wrap1 function takes T and return T.
Actual behavior:
typeof test11 is more generic than typeof test1. Meanwhile, wrap2 works as intended, except it doesn't have type constrain.

Playground Link:
Playground Link

Related Issues:
N/A

Metadata

Metadata

Assignees

Labels

BugA bug in TypeScriptFixedA PR has been merged for this issue

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions