-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
"If this was intentional, convert the expression to 'unknown' first" diagnostic should come with a codefix #28067
Comments
I'm interested in taking this issue. Any pointers you think would be helpful for a first-time Typescript contributor? |
Look at some existing simple codefixes like |
My fix for this issue is coming along nicely. In fact, I had finished and tested it before I noticed you wanted this to apply to TypeAssertions as well as AsExpressions. So I'm working on adding that functionality. Just to verify, |
|
I'm hoping you can clear up some confusion I'm having with this solution. I don't find the double assertion first to unknown and then to the type we want to be very elegant or even consistent with documentation. The basic basic types docs mentions in the type assertion section
Doing a double cast seems to go against the whole "trust me, I know what I'm doing" theory behind type assertions. Is the reason for this a technical limitation with the typescript compiler? |
It's "trust me I know what I'm doing" within means. We try to ensure there's some overlap, and if not you can do jump up and down the type hierarchy. |
Thanks for the response. I hope your team will reconsider this approach.
This seems to be the equivalent to having a double confirmation dialog in a UI. In this analogy I imagine a pop up box asking a user if they accept terms and conditions, and when they hit accept they are prompted again if they are sure they accept the terms and conditions. Just as that double confirmation is not a good user experience in a UI, having to double assert what you want is not a good user experience when programming. |
I hope we can switch this off in |
TypeScript Version: 3.2.0-dev.20181020
Code
Expected behavior:
Codefix to convert to
0 as unknown as string
.Actual behavior:
No codefix.
The text was updated successfully, but these errors were encountered: