-
Notifications
You must be signed in to change notification settings - Fork 23
Improve Deno project #111
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
Improve Deno project #111
Conversation
typescript-deno/deno.jsonc
Outdated
// https://github.com/guardian/csnx/blob/1be3fd98ed527ccf0f1b8e21f10039e23fdb3fb7/libs/%40guardian/tsconfig/tsconfig.json | ||
"compilerOptions": { | ||
"noImplicitReturns": true, | ||
"noUncheckedIndexedAccess": true, |
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.
I have a feeling this specific compiler option might create more friction than intended, as it is known to create false positives. The TypeScript development team have repeatedly resisted calls to make this rule a default due to its inflexibility; see here.
This appears to be an issue particularly when attempting to index into arrays in bounds-checked loops, see example in the docs
function screamLines(strs: string[]) {
// This will have issues
for (let i = 0; i < strs.length; i++) {
console.log(strs[i].toUpperCase());
// Object is possibly 'undefined'.
}
}
My experience doing coding exercise interviews is that candidates often reach for C-style for loops and this rule might end up creating more confusion than needed. I would therefore skip it if possible, but happy to hear your thoughts.
The other rules (noImplicitReturns
and noUnusedLocals
) seem like great additions.
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.
That’s a fair point… Do we think that this is an interesting point of discussion for interviews?
For any future candidate reading this, I’m sure you’ll make a good impression if you do this instead 😉:
function screamLines(strs: string[]) {
for (const str of strs) {
console.log(str.toUpperCase());
}
}
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.
In the game of life exercise it's extremely common to use indexing into a 2d array to find the neighbours in a grid, and it raises interesting questions about how to do it safely. For accessing neighbours in a 2d array of arrays how would you do that whilst keeping this rule happy?
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.
@michaelclapham simply by checking whether the value is not undefined
.
const grid = [
[1, 1, 0],
[0, 0, 0],
[1, 0, 1],
];
const safe = grid[0]?.[0] // number | undefined
if (typeof safe === "number") {
console.log("we know this is a safe lookup!", safe)
}
const unsafe = grid[9]?.[9] // number | undefined
if (typeof unsafe === "number") {
console.log("This will never happen!", unsafe)
}
This can easily throw errors that may not be valuable in the context of a code pairing test for our candidates Co-authored-by: Mario Savarese <[email protected]>
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.
Overall looks good!
What does this change?
How to test
deno task test
How can we measure success?
Up-to-date project
Have we considered potential risks?
N/A