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
However, fixing this causes #19576 to again break. I seems that having #19576 be an error is the lesser of two evils, but it would be nice to somehow keep around contra-variant inferences when the only co-variant inference we have is a never resulting from a freshly created array literal.
I'm still having issues with this, I think. You can see the error on this Playground example. Note that bad gives a compiler error.
The problem that lead me here is that const s: BehaviorSubject<number[]> = new BehaviorSubject([]); is an error if I turn strictFunctionTypes on. ("Type 'BehaviorSubject<never[]>' is not assignable to type 'BehaviorSubject<number[]>'.") I can't imagine that we really want everybody to have to write new BehaviorSubject([] as number[]) all over the place. Am I missing something?
TypeScript Version: [email protected]
Search Terms: Generic Type Inference Function Parameter Union
Code
Note: This case is common when passing comparators into functions.
Expected behavior:
T
should be inferred asFoo
.Actual behavior:
T
is expanded based on whatfunc
accepts.Playground Link: https://www.typescriptlang.org/play/index.html#src=interface%20Foo%20%7B%0A%20%20%20%20foo%3A%20number%3B%0A%7D%0A%0Adeclare%20function%20acceptUnion(foo%3A%20Foo%20%7C%20number)%3A%20void%3B%0Adeclare%20var%20foo%3A%20Foo%3B%0A%0Adeclare%20function%20erroneouslyExpands%3CT%3E(value%3A%20T%2C%20func%3A%20(t%3A%20T)%20%3D%3E%20void)%3A%20T%3B%0A%0Aconst%20test%3A%20Foo%20%3D%20erroneouslyExpands(foo%2C%20acceptUnion)%3B%0A
Related Issues:
The text was updated successfully, but these errors were encountered: