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

217
Visualizações
How to use Object.freeze in Vue with Typescript?

There is an example:

<template>
  <h1>hello</h1>
</template>

<script lang="ts">
import Vue from 'vue'

type DataOptions = {
  name: string
  age: number
  flags: { t: number; l: number }[]
}

export default Vue.extend({
  name: 'HelloWorld',

  data(): DataOptions {
    return {
      name: 'zs',
      age: 18,
      flags: []
    }
  },

  methods: {
    refresh() {
      const response = [
        { t: 1, l: 1 },
        { t: 2, l: 2 }
      ]

      this.flags = Object.freeze(response)
    }
  }
})
</script>

Typescript will report: The type 'readonly { t: number; l: number; }[]' is 'readonly' and cannot be assigned to the mutable type '{ t: string; l: string; }[]'.

over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

Make your data property flags as a readonly array in order to assign response to it :

type DataOptions = {
  name: string
  age: number
  flags: ReadonlyArray<Record<'t'|'l', number>>
}
over 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