Contextual never
parameter type gets precedence over the initializer's type
#56505
Labels
Possible Improvement
The current behavior isn't wrong, but it's possible to see that it might be better in some cases
π Search Terms
contextual parameter type initializer never
π Version & Regression Information
β― Playground Link
https://www.typescriptlang.org/play?ts=5.4.0-dev.20231122#code/CYUwxgNghgTiAEAzArgOzAFwJYHtXwxAGcMAeAKHngBUBhPQgDwwBpKaBZEDACx2CLwQzEKgHwASuBwxgpEjCyoA5i3gAKTIwBcNeqiat4AOlOxlRXahAA3EDADaAXQCU8ALwA+eGgDWqHAB3VE82T00GYQxdOkjmNQBbbj4BGK5efiIXXRscLGAAbnJyQhJ1dgBvdiowHDRo+AAGNioAXxb4KqoannBfABksBKwGzQxGRKhGD3gAVkbGty9O9ur4HigiAEEwMGJLDS01ZCJ7XQr4VCgk3QUlZXhWpe8K1ba2FyKgA
π» Code
π Actual behavior
never
gets assigned as the type ofmax
parameter and TS errors on the initializer's type mismatch:π Expected behavior
I'd expect the type inferred from the initializer to take precedence over
never
here. After all, we could annotate this contravariant position withmax: number = 500
and that wouldn't violate any constraints.Additional information about the issue
No response
The text was updated successfully, but these errors were encountered: