skip to Main Content

I was wondering how can I convert this little snippet from typescript into JS.

<script setup lang="ts">
  import { type Content } from '@prismicio/client';

  defineProps(
    getSliceComponentProps<Content.HeroSlice>([
      "slice",
    ]),
  );
</script>

3

Answers


  1. I think it worked and you need to use type in import because using typescript :

    <script setup lang="ts">
      import { type Content } from '@prismicio/client';
    
      defineProps(
        getSliceComponentProps<Content.HeroSlice>([
          "slice",
        ]),
      );
    </script>
    
    Login or Signup to reply.
  2. This should be working well

    <script setup>
    import * as prismic from '@prismicio/client'
    
    defineProps(getSliceComponentProps(["slice"]))
    </script>
    

    More info can be found in the docs.

    Since you’re not typing it, you don’t even need the Content in the TS generic.
    Use prismic.[your method] to do your usual Prismic stuff.

    Login or Signup to reply.
  3. TypeScript uses types and interfaces that are not recognized by pure JavaScript. So my friend, you need to remove type declarations, keep imports because modern JavaScript (ES6) supports imports.`
    import { Content } from ‘@prismicio/client’;

    const props = getSliceComponentProps(["slice"]);
    `

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search