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
I have an overloaded method that has two distinct signatures. One signature is a generic that returns the invoked argument (e.g. returns some element in an encapsulation container). If I construct a type that is a union of this generic type (e.g. Encapsulator<number> | Encapsulator<string>), I see some odd behavior. If I removed the un-used overloaded method signature, there are no errors.
Simplified example on flow.org/try. Remove line 12 and type checking succeeds.
type Encapsulator<T> = {
(): T
};
function encapsulate<TToEncapsulate>(obj: TToEncapsulate): Encapsulator<TToEncapsulate> {
return () => obj;
}
type ExtractReturnType = <V>(() => V) => V;
declare class Deencapsulator {
provide<T: Encapsulator<*>>(encapsulated: T): $Call<ExtractReturnType, T>,
provide(num: number): number
}
const instance = new Deencapsulator();
type EncapsulatedOrNumber = Encapsulator<string> | Encapsulator<number>;
const whoKnows: EncapsulatedOrNumber = ({}: any);
const stringOrNumber = instance.provide(whoKnows);
Yields the following error:
19: const stringOrNumber = instance.provide(whoKnows);
^ Cannot call `instance.provide` because number [1] is incompatible with string [2] in type argument `T` [3] of type argument `T`.
References:
17: type EncapsulatedOrNumber = Encapsulator<string> | Encapsulator<number>;
^ [1]
17: type EncapsulatedOrNumber = Encapsulator<string> | Encapsulator<number>;
^ [2]
1: type Encapsulator<T> = {
^ [3]
Commenting out provide(num: number): number yields no errors.
The text was updated successfully, but these errors were encountered:
I have an overloaded method that has two distinct signatures. One signature is a generic that returns the invoked argument (e.g. returns some element in an encapsulation container). If I construct a type that is a union of this generic type (e.g.
Encapsulator<number> | Encapsulator<string>
), I see some odd behavior. If I removed the un-used overloaded method signature, there are no errors.Simplified example on flow.org/try. Remove line 12 and type checking succeeds.
Yields the following error:
Commenting out
provide(num: number): number
yields no errors.The text was updated successfully, but these errors were encountered: