-
Notifications
You must be signed in to change notification settings - Fork 12.8k
No error on unconstrained type parameter in >
comparison
#50603
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
This is expected behavior in 4.8. See this section in the blog post: https://devblogs.microsoft.com/typescript/announcing-typescript-4-8/#unconstrained-generics-no-longer-assignable-to You probably want to change your type variable to be constrained to |
Ah, interesting! Where's the For example, I'm confused why there's no error here: function f<T>(a: T, b: T): boolean {
return a > b;
} |
Honestly, I didn't even notice that the operator you used was function f<T>(a: T, b: T): boolean {
if (a === undefined} {
return true;
}
return a > b;
} In that it's odd that we allow |
The current behavior is clearly inconsistent. If you canβt use |
T | null
)>
comparison
Note that the issue reported here also exists for the function foo<T>(x: T) {
+x; // Ok
if (x === undefined) return;
+x; // Error
} With #59437, errors are reported in both cases above. |
Bug Report
π Search Terms
object is possibly undefined 4.8
π Version & Regression Information
β― Playground Link
TS playground on 4.8.0-beta link.
(The playground doesn't seem to have 4.8.x releases, but I tested on 4.8.0-beta and nightly (4.9.0-dev.XXXXXXX).)
π» Code
On that line, hovering over the first
result
showsT | null
. Hovering over the secondresult
showsT & ({} | undefined)
.π Actual behavior
I get a type error.
π Expected behavior
No error.
The text was updated successfully, but these errors were encountered: