I have this problem with typescript and can not understand what is wrong:
type Dogs = {bark: true};
type Cats = {meow: true};
........
.then((data: [Dogs, Cats][]) => {
const [dogs, cats] = data;
display(dogs, cats));
})
........
const display = (dogs: any, cats: any) => {
return ....
}
For now, everything is ok. When display function is written like this (dogs: any, cats: any) everything is fine, but if I change display function to:
const display = (dogs: Dogs, cats: Cats) => {
return ....
}
I receive an error in destructuring line (const [dogs, cats] = data;) that "dogs doesn't have meow key and cats doesn't have bark key"???
What I'm doing wrong?
.then((data: [Dogs, Cats]) => {you miswrote your typedata: [Dogs, Cats][]is an array of tuples, each tuple is[Dogs, Cats]. If you destructure asconst [dogs, cats] = data;thendogswill hold the first tuple andcatswill hold the second tuple. I'm not sure what you need but it's likely not an array of tuples. Either a plain tuple or an array.thenyou are trying to deconstruct array of arrays into two variables. Each variable interpreted like array. So you should try justdata: [Dogs, Cats].