[Vuejs]-Typing HTML Attributes in Vue 3 with TypeScript

1👍

Every key-value on $attrs is typed as Record<string, unknown>, so TypeScript will need your help understanding the actual type if you’re using them in your code, either in the script or in the template which can be done like this:

<template>
  <label :for="($attrs.id as string)">{{ label }}</label>
  <input :id="($attrs.id as string)" type="checkbox" />
</template>
👤yoduh

Leave a comment