Skip to content

Fail to get contextual type when an index signature exists #27949

Closed
@ghost

Description

TypeScript Version: 3.2.0-dev.20181017

Code

interface Options {
    m(x: number): void;
    [key: string]: unknown;
}
declare function f(options: number | Options): void;
f({
    m(x) {},
});

Expected behavior:

No error.

Actual behavior:

src/a.ts:7:7 - error TS7006: Parameter 'x' implicitly has an 'any' type.

Was introduced by #27849. For some reason it only happens when options is a union. Discovered in jquery on DefinitelyTyped.

Metadata

Metadata

Assignees

Labels

BugA bug in TypeScriptDomain: Contextual TypesThe issue relates to contextual typesFixedA 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