Skip to content

Feat: added content to Lesson13.java - James Capparell #439

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

Closed
wants to merge 9 commits into from

Conversation

jjcapparell
Copy link
Contributor

No description provided.

}
for (const key of stringS.keys()) {
if (stringT.has(key)) {
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't need to disable the assertions, please remove.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll find a solution right away. I was having trouble with it yesterday and was causing an error. It was a quick fix that VS code suggested for those lines. Do you have any suggestions on how to fix it or do you think just removing the comments will work still?

Copy link
Contributor Author

@jjcapparell jjcapparell Oct 25, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I made changes thinking that the build ran with removing those lines but it never actually pushed those changes correctly. The typescript file now has an error after removing those lines.

}
for (const key of stringS.keys()) {
if (stringT.has(key)) {
const value1 = stringS.get(key)!; // Non-null assertion because we checked with has()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The error is saying you can't use ! and instead need to do something different. The documentation for the error (https://typescript-eslint.io/rules/no-non-null-assertion/) gives you an example of what you can do instead.

Re-writing as stringS.get(key) ?? -1 would work perfectly fine.

Unfortunately, the TypeScript compiler isn't smart enough yet to figure out that the has check you did on line 10 means that the check on line 11 is safe. There's probably an open feature request for this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants