Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

399
Views
Purpose of '@typescript-eslint/no-non-null-assertion' when disabling a button

In this block of code, what is the .value! and @typescript-eslint/no-non-null-assertion doing? The documentation is too abstract for me to connect to the context of this button behavior.

const submitButton = ref<HTMLButtonElement | null>(null);

  //Disable button
  /* eslint-disable  @typescript-eslint/no-non-null-assertion */
  submitButton.value!.disabled = true;

P.S. Only in programming can you say "no-non-null" with a straight face.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

The ! is a typescript non-null assertion. It tells typescript "I know it looks like value might be a null, but trust me, it's not". This can be useful if you know something that typescript does not (in this case, you presumably know that the ref will be populated before this code runs), but it essentially turns off type checking on this line, and so can accidentally introduce bugs.

Since the non-null assertion is risky, there is a lint rule which can be used to ban their use. The lint rule, when enabled, will flag this line as a problem. The typical fix would be to then write code to check for null, so that no assertion is needed. But if you want to, you can tell eslint not to check this line, via a special comment like /* eslint-disable @typescript-eslint/no-non-null-assertion */.

So in summary, these lines are saying "Hey typescript, don't check this. Hey eslint, don't check this".

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!