Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

244
Visualizações
Pinia store in Typescript Vue component gives error "Property 'testStore' does not exist on type 'CreateComponentPublicInstance'...."

I've a <script setup> block in which I import my testStore but whenever I want to use this.testStore.name somewhere in my vue file vetur gives me this error:

Property 'testStore' does not exist on type 'CreateComponentPublicInstance<{ [x: string & `on${string}`]: ((...args: any[]) => any) | undefined; } | { [x: string & `on${string}`]: undefined; }, {}, {}, {}, {}, ComponentOptionsMixin, ComponentOptionsMixin, ... 10 more ..., {}>'.
  Property 'testStore' does not exist on type '{ $: ComponentInternalInstance; $data: {}; $props: { [x: string & `on${string}`]: ((...args: any[]) => any) | undefined; } | { [x: string & `on${string}`]: undefined; }; ... 10 more ...; $watch(source: string | Function, cb: Function, options?: WatchOptions<...> | undefined): WatchStopHandle; } & { ...; } & ShallowU...'.Vetur(2339)

Since I'm a typescript n00b I don't really know how to fix this and the Pinia docs don't really seem to help me out on this matter(I can only find how I can make a shim for custom properties but nothing about having to define my stores or something).

this is my pinia store file(testStore.ts)

import { defineStore } from 'pinia';

const state = () => ({
  name: 'This is my store'
});

const actions = {};

const getters = {
};
export const useTestStore = defineStore('testStore', {
  state,
  getters,
  actions,
});

This is my .vue file

<script setup lang="ts">
import { defineComponent } from 'vue'
import { useTestStore } from '@/stores/testStore';
const testStore = useTestStore();
</script>
<template>
  {{ testStore.name }}
</template>
<script lang="ts">
export default defineComponent({
  name: 'testStore',
  mounted () {
    console.log(this.testStore.name)
  }
});
</script>
about 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

I think your code should be

<script setup lang="ts">
  import { defineComponent } from 'vue'
  import { useTestStore } from '@/stores/testStore';
  
  const testStore = useTestStore();

  console.log(testStore); // testStore should displayed
</script>

<template>
  {{ testStore.name }}
</template>

Notice:

<script setup lang="ts"></script>

and

<script lang="ts">
  export default defineComponent({});
</script>

Both are used to define components, use one of them, don't use both.

Some Vue doc that you might need:

https://vuejs.org/guide/typescript/composition-api.html

https://vuejs.org/guide/typescript/options-api.html

about 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda