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
The type of error is inferred as null in line 11 and unknown in line 12. This is wrong because there is a potential assignment to error` in the local lambda.
π Expected behavior
The type of error should be Error|null after the onError call as there is a potential assignment happening in the callback. Its understandable if the analyzer cannot widen the type if the passed callback is again some other function or method but for local lamdbas it could be treated like a "conditional" which might be met. e.g. in the following example error is widened to Error|null
π Search Terms
type, infer, lambda, callback
π Version & Regression Information
β― Playground Link
https://www.typescriptlang.org/play/?ts=5.7.3#code/GYVwdgxgLglg9mABAgogJzXNAKAFgQzABMAbAUzQC5Fszr1M0BKRAXgD5EA3OGIlgN4BYAFCJxiAsXI4wZAO6IGWbEyYBuUQF9Ro8lEQVGlZWgA+YECRJtEl65pGjUGFWTadhYiUay2yjloauiIwwLSuaIgAhKysdlYkgqISiFC4mIq+aIGiQA
π» Code
π Actual behavior
The type of
error
is inferred asnull
in line 11 andunknown in line 12. This is wrong because there is a potential assignment to
error` in the local lambda.π Expected behavior
The type of
error
should beError|null
after theonError
call as there is a potential assignment happening in the callback. Its understandable if the analyzer cannot widen the type if the passed callback is again some other function or method but for local lamdbas it could be treated like a "conditional" which might be met. e.g. in the following exampleerror
is widened toError|null
Additional information about the issue
One workaround I currently have is to add
error = error as Error | null;
somewhere.The text was updated successfully, but these errors were encountered: