Subscribe on changes!

Vue ref macros conflict with `@typescript-eslint/no-unnecessary-condition` linting rule

avatar
Jun 6th 2022

Vue version

3.2.37

Link to minimal reproduction

https://stackblitz.com/edit/vitejs-vite-kltxrc?file=src/main.ts

Steps to reproduce

Run npm run lint (which runs eslint src/main.ts)

What is expected?

No lint errors for the following code:

import { $ref } from 'vue/macros'

const a = $ref<boolean>(false)
if (a) {
  
}

What is actually happening?

The following lint error:

/home/projects/vitejs-vite-kltxrc/src/main.ts
  4:5  error  Unnecessary conditional, value is always truthy  @typescript-eslint/no-unnecessary-condition

✖ 1 problem (1 error, 0 warnings)

System Info

No response

Any additional comments?

No response

avatar
Jun 8th 2022

That's a bug in @typescript-eslint because TypeScript itself doesn't consider the condition to be always true.