-
Notifications
You must be signed in to change notification settings - Fork 12.5k
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
Type Narrowing for hasAttribute and getAttribute #22238
Comments
I believe this would be an (very complex, but possible) override of |
Duplicate of #18781 and #13086. I do nto think we want to add such overloads to the library, but you are welcomed to add them. @DanielRosenwasser has a sample how |
@mhegazy Isn't |
It's the same kinda situation; the types would look identical. |
Automatically closing this issue for housekeeping purposes. The issue labels indicate that it is unactionable at the moment or has already been addressed. |
TypeScript Version: 2.7.1 and 2.8.0-insiders.20180127
Type guard should catch
hasAttribute
so thatgetAttribute
doesn't return null.In the following example, TS still says
getAttribute
couldreturn null
, however we previously checked for the attribute on the previous line.Expected Result:
element.getAttribute('data-title')
Return type should bestring
Actual Result:
element.getAttribute('data-title')
Return type isstring | null
The text was updated successfully, but these errors were encountered: