S
S
SM_ST2021-11-24 15:24:31
Vue.js
SM_ST, 2021-11-24 15:24:31

TypeScript how to properly remove errors?

Tell me how to remove the error that hung over this line

selected.value.push(el)

Argument of type 'any' is not assignable to parameter of type 'never'.Vetur(2345)
const el: any
const el: any


?

Just started learning about TypeScript

<script lang="ts">
import { defineComponent, useStore, ref } from '@nuxtjs/composition-api'
export default defineComponent({
  setup() {
    const parentCategories = ref([])
    const categories = ref([])
    const selected = ref([])

    const store = useStore()

    categories.value = store.getters.GET_CATEGORIES

    parentCategories.value = getParentCategories()

    const changeCategory = (id: Number) => {
      const el: any = categories.value.find((el: any) => el.id === id)

      if (!el) return false

      const children = categories.value.filter(
        (item: any) => item.parentId === el.id
      )

      if (children.length > 0) {
        parentCategories.value = categories.value.filter(
          (item: any) => item.parentId === el.id
        )
        selected.value.push(el)
      } else {
        store.dispatch('SET_CATEGORY_MODAL_SELECTED', el)
        closeModal()
      }
    }

    const prevCategory = (id: Number) => {
      const categorySelected: any = categories.value.find(
        (el: any) => el.id === id
      )

      if (!categorySelected) return false

      if (categorySelected.parentId === 0) {
        parentCategories.value = getParentCategories()
        selected.value = []
      } else {
        parentCategories.value = categories.value.filter(
          (item: any) => item.id === categorySelected.parentId
        )
      }
    }

    const closeModal = () => {
      store.dispatch('OPEN_CATEGORY_MODAL', false)
    }

    function getParentCategories() {
      return categories.value.filter((item: any) => item.parentId === 0)
    }

    return {
      closeModal,
      changeCategory,
      prevCategory,
      selected,
      parentCategories,
    }
  },
})
</script>

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question