Skip to content

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

Closed

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.

Activity

  1. ghost added
    BugA bug in TypeScript
    on Oct 17, 2018
  2. added
    FixedA PR has been merged for this issue
    Design LimitationConstraints of the existing architecture prevent this from being fixed
    and removed
    Design LimitationConstraints of the existing architecture prevent this from being fixed
    on Oct 17, 2018
  3. added a commit that references this issue on Oct 17, 2018
    31f4053
  4. locked as resolved and limited conversation to collaborators on Oct 21, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

BugA bug in TypeScriptDomain: check: 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