Closed
Description
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)