Skip to content

Inference from multiple signatures produces unknown instead of any #31189

Closed
@sandersn

Description

@sandersn

#30637 breaks webpack in 3 places in a method chain starting with anys.filter(Boolean).reduce(.... Discovered by the user tests.

Note that this stops happening when there is only one signature. As soon as there are multiple signatures of either kind, it repros.

Code
(Edit: switched to isolated repro)

interface Bullean { }
interface BulleanConstructor {
    new(value?: any): Bullean;
    <T>(value?: T): value is T;
}

interface Ari<T> {
    filter<S extends T>(callbackfn: (value: T) => value is S): Ari<S>;
    filter(callbackfn: (value: T) => unknown): Ari<T>;
}
declare var Bullean: BulleanConstructor;
declare let anys: Ari<any>;
var xs: Ari<any>;
var xs = anys.filter(Bullean); // error in 3.5: Ari<unknown>, from first overload of filter.

h/t @RyanCavanaugh for the type name Bullean

Expected behavior:
xs : any[]

Actual behavior:
xs : unknown[]

Metadata

Metadata

Assignees

Labels

BugA bug in TypeScriptFixedA PR has been merged for this issue

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions