TypeScript/tests/cases/compiler/varianceCallbacksAndIndexedAccesses.ts
Wesley Wigham 0dbad04c3f
Distribute indexed accesses when simplifying them (#26281)
* unknownify accesses

* Move to simplify to break less with fewer changes

* Accept baselines for now

* Always propegate any as an index type

* Fix flow control in the presence of simplifiable types

* Add spy repro from #25181

* Retain errorType when it is used as a marker for the lack of a constraint

* Small refinement

* Add new test

* Move most potentially recursive types from isIdenticalTo into structuredTypeRelatedTo to match the non-identity relations

* Fix nits

* Doesnt need to be undefineable at all
2018-08-27 13:32:01 -07:00

32 lines
1.1 KiB
TypeScript

type Source = {
<K extends keyof WindowEventMap>(type: K, listener: (this: Window, ev: WindowEventMap[K]) => any, options?: boolean | AddEventListenerOptions): void;
(type: string, listener: EventListenerOrEventListenerObject, options?: boolean | AddEventListenerOptions): void;
}
interface Action1<T> {
(arg: T): void;
}
interface MessageEventLike<T> {
source: WindowLike<T>;
origin: string;
data: T;
}
interface PostMessageObject<T> {
postMessage(message: T, host: string): void;
}
interface WindowLike<T> extends PostMessageObject<T> {
addEventListener(type: "message", handler: Action1<MessageEventLike<T>>): void;
addEventListener(type: string, handler: Action1<any>): void;
removeEventListener(type: "message", handler: Action1<MessageEventLike<T>>): void;
removeEventListener(type: string, handler: Action1<any>): void;
}
type Target = {
(type: "message", handler: Action1<MessageEventLike<any>>): void;
(type: string, handler: Action1<any>): void;
};
function f1(s: Source, t: Target) {
t = s;
}