Open download13 opened 3 years ago
type Type1 = number
type Type2 = string
type CompoundType = Type1 | Type2;
const first: Type1 = 1;
const first$ = xs.of(first);
const x$: Stream<CompoundType> = first$; // this gives an error
This is due strictFunctionTypes
enabled.
But probably it still should be considered as buggy behavior and as can be avoided. I see no reason why Stream<number>
should not be actually not assignable to Stream<number | string>
.
With xstream
it is caused by having visible internal props with InternalListener<T>
on the class:
protected _ils: Array<InternalListener<T>>;
protected _dl: InternalListener<T>;
@staltz ?
related issues: https://github.com/staltz/xstream/issues/286
I made a PR for this https://github.com/staltz/xstream/pull/317
When
merge
ing streams of component types of a discriminating union the internal listener seems to be trying to assign a variable of the compound type to a variable of a component type.You can see in the example repository I made that typechecking produces the following error:
Basically, it seems like
merge
won't output types compatible with theCompoundType
even when all of it's input stream are of component types. It works if merge contains all of the component types however. You can test it by addingsecond$
to thexs.merge
call.Is this intentional for a reason I don't understand, or is it a bug? I ran into it while converting DOM events into
Action
s to feed into my reducer function in a cyclejs app.EDIT: Might be related to https://github.com/staltz/xstream/issues/262#issuecomment-615875854