Skip to content

docs(eslint-plugin): [no-non-null-assertion] correct example #2188

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

Merged
merged 1 commit into from
Jun 8, 2020

Conversation

rhysd
Copy link
Contributor

@rhysd rhysd commented Jun 8, 2020

Previous example

const includesBaz: boolean = foo.bar && foo.bar.includes('baz');

does not compile with --strictNullChecks because type of foo.bar && foo.bar.includes('baz') is boolean | undefined. Instead, using null coalescing operator and optional chaining is better example for safer and idiomatic TypeScript code.

const includesBaz: boolean = foo.bar?.includes('baz') ?? false;

@typescript-eslint
Copy link
Contributor

Thanks for the PR, @rhysd!

typescript-eslint is a 100% community driven project, and we are incredibly grateful that you are contributing to that community.

The core maintainers work on this in their personal time, so please understand that it may not be possible for them to review your work immediately.

Thanks again!


🙏 Please, if you or your company is finding typescript-eslint valuable, help us sustain the project by sponsoring it transparently on https://opencollective.com/typescript-eslint. As a thank you, your profile/company logo will be added to our main README which receives thousands of unique visitors per day.

@codecov
Copy link

codecov bot commented Jun 8, 2020

Codecov Report

Merging #2188 into master will not change coverage.
The diff coverage is n/a.

@@           Coverage Diff           @@
##           master    #2188   +/-   ##
=======================================
  Coverage   93.42%   93.42%           
=======================================
  Files         173      173           
  Lines        7861     7861           
  Branches     2242     2242           
=======================================
  Hits         7344     7344           
  Misses        245      245           
  Partials      272      272           
Flag Coverage Δ
#unittest 93.42% <ø> (ø)

@bradzacher bradzacher added the documentation Documentation ("docs") that needs adding/updating label Jun 8, 2020
Copy link
Member

@bradzacher bradzacher left a comment

Choose a reason for hiding this comment

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

thanks!

@bradzacher bradzacher changed the title docs(eslint-plugin): better correct example for no-non-null-assertion docs(eslint-plugin): [no-non-null-assertion] correct example Jun 8, 2020
@bradzacher bradzacher merged commit d8ff5de into typescript-eslint:master Jun 8, 2020
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jul 9, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
documentation Documentation ("docs") that needs adding/updating
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants