Q
Q
QWERTY012022-03-27 13:15:53
typescript
QWERTY01, 2022-03-27 13:15:53

Why are there no errors in vue 3 despite different data types on asynchronous request?

1. Interface file

export interface CategoriesInterface {
  base: number,
  date: string,
  rates: {
    [key: string]: number
  },
  success: boolean,
  timestamp: number
}


2. file with assignment.
Here the currency.value variable is assigned the result of the asynchronous request
<script lang="ts">
 import { ref, onMounted } from 'vue'
import { CategoriesInterface } from '@/interface/currency-interface'

 export default {
   name: 'Home',
   const currency = ref<CategoriesInterface | null>(null)
  
    onMounted(async () => {
      currency.value = await store.dispatch('fetchCurrency')
    })
}
</script>


3. The following object comes from the request,
that is, in the interface, the base field is set to the number type, and the string (base: 'EUR') comes and there is no error in the console.
{
        base: 'EUR',
        date: '2022-03-27',
        rates: {
          EUR: 1,
          RUB: 112,
          USD: 1
        },
        success: true,
        timestamp: 1648371543
      }


4. the vuex file where the request happens
********
actions: {
    async fetchCurrency() {
      const { data } = await axios(`http://ссылка`)
      return data
    }
  }
************


For the test, I tried to copy the object that comes from the request and manually insert it into currency.value, then the error appears, but if the same object comes through a request to the server, then there are no typing errors

Answer the question

In order to leave comments, you need to log in

1 answer(s)
W
wonderingpeanut, 2022-03-27
@QWERTY01

I assume that the return type of the fetchCurrency function is any.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question