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
Refactor to turn on noUncheckedIndexedAccess
option for TypeScript
#5983
Conversation
@@ -117,7 +117,7 @@ function longer(hex) { | |||
let hexVariant = '#'; | |||
|
|||
for (let i = 1; i < hex.length; i++) { | |||
hexVariant += hex[i] + hex[i]; | |||
hexVariant += hex.charAt(i).repeat(2); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[note] .charAt()
always returns a string (e.g. an empty string).
for (let i = 0; i < lines.length; i++) { | ||
let line = lines[i]; | ||
|
||
for (let [i, line] of lines.entries()) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[note] .entries()
makes a traditional for
loop much readable.
@@ -110,16 +110,20 @@ const rule = (primary, secondaryOptions) => { | |||
* @returns {boolean} | |||
*/ | |||
function hasInterpolatingAmpersand(selector) { | |||
for (let i = 0, l = selector.length; i < l; i++) { | |||
if (selector[i] !== '&') { | |||
for (const [i, char] of Array.from(selector).entries()) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[note] Array.from()
can make a string to an array of characters.
The CI is now all green. ✅ |
noUncheckedIndexedAccess
option for TypeScriptnoUncheckedIndexedAccess
option for TypeScript
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is fantastic work, thank you!
Having this option enabled will likely catch bugs that we've fallen foul to in the past.
@jeddy3 Thank you for reviewing the big pull request! 😄 |
https://www.typescriptlang.org/tsconfig#noUncheckedIndexedAccess
Ref: #5982 (comment)
The
noUncheckedIndexedAccess
option allows us to detect potential bugs like #5982, e.g.Note: This pull request just helps us to see the errors if
noUncheckedIndexedAccess
is turned on. We cannot merge it now.See https://www.typescriptlang.org/tsconfig#noUncheckedIndexedAccess
EDIT: If you want to try it on a branch other than this one, you can use the CLI flag
--noUncheckedIndexedAccess
, for example:$ npm run lint:types -- --noUncheckedIndexedAccess