typescript:S6598 might be a false-positive for interface Emits macro in .vue files

  • What language is this for?
    Vue3, TypeScript

  • Which rule?
    Interface has only a call signature, you should use a function type instead (typescript:S6598)

  • Why do you believe it’s a false-positive/false-negative?
    In Vue3, you can define compiler macros. One of them which we did earlier was instead of defining the type/interface in defineEmits. Vue3 you can define Emits using interface

  • Are you using

    • SonarQube Cloud? - YES
  • How can we reproduce the problem? Give us a self-contained snippet of code (formatted text, no screenshots)

If you create a simple Vue3 app and define the emits as follows:

interface Emits {
     (e: 'emit-a'): void;
     (e: 'emit-b', param: string): void;
}
const emits = defineEmits<Emits>();

and run Sonarcloud on this code, you should get the warning for the typescript:S6598

@rpandya, thanks for the report.

I tried to reproduce the issue using the following .vue code, hopefully exactly the same one as your screenshot:

<script setup lang="ts">
const emit = defineEmits<{
  (e: 'change', id: number): void
  (e: 'update', value: string): void
}>()
</script>

I was not able to have S6598 raised either with SonarQube or SonarLint.

The following sample raises as expected:

<script setup lang="ts">
const emit = defineEmits<{
  (e: 'change', id: number): void
}>()
</script>

Is there something that I am missing?

2 Likes