Home > Mobile >  Use a typed Bootstrap Modal variable in vue 3 sfc
Use a typed Bootstrap Modal variable in vue 3 sfc

Time:10-27

I am new to typescript and vue 3 js. I wrote a single-file-component and want to use a Bootstrap 5 modal. But my VSCode shows a error on my declared variable type. The error says:

"Modal" refers to a value, but is used here as a type. Did you mean "type of modal"?

<script setup lang="ts">
   import { Modal } from "bootstrap";
   let modal: Modal = null;
   ...
</script>

I install via npm bootstrap and all JS type from bootstrap with

npm install --save-dev @types/bootstrap

Has anyone a idea?

CodePudding user response:

Are you missing a typeof operator?

<script setup lang="ts">
   ...
   let modal: typeof Modal = null;
   ...
</script>

CodePudding user response:

import type of modal only

   import type { Modal } from "bootstrap";
  • Related