This is an anti-pattern on the current type system. And the compiler must not do quick fix so. !. after ?. is simply replaceable with ?. and should do so.
TypeScript Version: 3.7.x-dev.20191105
Search Terms:
Code
document.querySelector('_')!.textContent!.split('') // old code
document.querySelector('_')?.textContent!.split('') ?? 0 // string[]
document.querySelector('_')?.textContent?.split('') ?? 0 // string[] | 0
Expected behavior:
document.querySelector('_')!.textContent!.split('') // old code
document.querySelector('_')?.textContent!.split('') ?? 0 // unsafe, warning
document.querySelector('_')?.textContent?.split('') ?? 0 // safe
Actual behavior:
document.querySelector('_')!.textContent!.split('') // old code
document.querySelector('_')?.textContent!.split('') ?? 0 // unsafe, no warning
document.querySelector('_')?.textContent?.split('') ?? 0 // safe
Playground Link:
Related Issues:
Isn't this a just linting rule? Whenever you use ! it is potentially unsafe. The compiler never warns, an error is an error.
When quick fix observes this rule, it is wasteful splitting.
@falsandtru some discussion about what exactly is different between this and #35025 would be nice
This issue has meaning without adopting #35025 and meaningless if #35025 is adopted. So this issue and #35025 are in opposition. This is the definitive difference.
Most helpful comment
This issue has meaning without adopting #35025 and meaningless if #35025 is adopted. So this issue and #35025 are in opposition. This is the definitive difference.