Skip to content

Unsimpilifed Interesction Types Prevent Type Inference #12289

Closed
@ethanresnick

Description

@ethanresnick

TypeScript Version: 2.2.0-dev.20161112

Code

type Method = 'get' | 'post';
type Method2 = ('get' & string) | ('post' & string)

let app = {
    get() { },
    post() { }
};

let methodA: Method = 'get';
let methodB: Method2 = 'get';

let handlerA = app[methodA]; // () => void
let handlerB = app[methodB]; // Error: Element implicitly has an any type because `{ get(): void, post(): void}` has no index signature

Expected behavior:
handlerA and handlerB should have the same type inferred (because Method and Method2 should be treated as the same type, by simplifying Method2 down to Method).

Actual behavior:
handlerA is inferred correctly; handlerB errors/is implicitly any.

For context, here's the real code (and my attempt to fix it) that produced this problem: #12253 (comment)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Working as IntendedThe behavior described is the intended behavior; this is not a bug

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions