Skip to content

Generic argument inference no longer working for specific case #39080

Closed
@MPeloquin

Description

@MPeloquin

TypeScript Version: >3.9.2

Search Terms: generic argument inference TS2345

Code

declare namespace React {
    type WeakValidationMap<T> = {
        [K in keyof T]?: null extends T[K] ? string : string
    };

    interface FunctionComponent<P = {}> {
        propTypes?: WeakValidationMap<P>;
    }
}

type A<T1> = <T2>() => React.FunctionComponent<T1 & T2>;

function B<T>(_: A<T>) {}

interface C {
    r: String;
}

function myFunction<T2>(): React.FunctionComponent<C & T2> {
    return {};
}

B(myFunction) // Error
B<C>(myFunction) // No error

Expected behavior: In v3.8.3, the code above did not have any compilation error.

Actual behavior: Compilation error TS2345 when I do not explicitly pass the generic type.

Playground Link: Link

Note: I use React, here I only included the minimal React interfaces to reproduce the issue. The issue is also reproducible with React code directly here

Metadata

Metadata

Assignees

Labels

Fix AvailableA PR has been opened for this issueNeeds InvestigationThis issue needs a team member to investigate its status.RescheduledThis issue was previously scheduled to an earlier milestone

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions