You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Intersection type bug around polymorphic type aliases #342
/* @flow */
type Observable<T> = { observe(observer: Observer<T>): void }
type Observer<T> = { next(x: T): void }
type Subject<T> = Observable<T> & Observer<T>
function createSubject<T>(): Subject<T> {
var observers = []
return {
observe(observer) {
observers.push(observer)
},
next(x) {
for (var i = 0; i < observers.length; i++) {
observers[i].next(x)
}
}
}
}
type Test = {
foo: Observable<string>
}
function test(): Test {
var foo: Subject<string> = createSubject()
return { foo }
}
test2.js|5 col 19 error| intersection type
|| This type is incompatible with
test2.js|3 col 22 error| object type
||
test2.js|5 col 19 error| intersection type
|| This type is incompatible with
test2.js|4 col 20 error| object type
||
@samwgoldman This issue has been fixed (both your examples work without errors), hence closing.
There are other problems remaining with intersection types, but they could be tracked separately. (The test says what you tried should more or less work, but Subject may not be passable to an object type that has both next and observe.)
Activity
samwgoldman commentedon Mar 26, 2015
If I define
Subject<T>without intersections, but just inlining the definitions fromObservable<T>andObserver<T>, then I receive no errors.samwgoldman commentedon Mar 27, 2015
I was actually able to simplify the test case. The whole Test structure is a red herring.
(EDIT: even simpler without the
createSubjectfunction.)samwgoldman commentedon Mar 27, 2015
Is this the same issue as identified in this intersection test?
avikchaudhuri commentedon Jun 19, 2015
@samwgoldman This issue has been fixed (both your examples work without errors), hence closing.
There are other problems remaining with intersection types, but they could be tracked separately. (The test says what you tried should more or less work, but Subject may not be passable to an object type that has both next and observe.)