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

Infer declarations are allowed in generic constraints, but do not infer generic constraint types #41040

Copy link
Copy link
@lazytype

Description

@lazytype
Issue body actions

TypeScript Version: 4.0.2

Search Terms: generic constraint, extends infer

Code

type InferGenericConstraint<Fn> = 
    Fn extends <T extends infer Constraint>(arg: T) => any
        ? Constraint
        : never;

type GenericFunctionExample = <T extends number>(arg: T) => void;

type InferredConstraint = InferGenericConstraint<GenericFunctionExample>;

Expected behavior:

  • Preferred: InferredConstraint is number.
  • Alternative: infer declaration is disallowed within a generic constraint clause.

Actual behavior: InferredConstraint is never

Playground Link: https://tsplay.dev/gWoYlN

Related Issues: #1213

Reactions are currently unavailable

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugA bug in TypeScriptA bug in TypeScriptDomain: check: Type InferenceRelated to type inference performed during signature resolution or `infer` type resolutionRelated to type inference performed during signature resolution or `infer` type resolution

    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.