Ts data type check error Type 'void' is not assignable to type' never []'.

recently started using typescript. But the damn code that did not report an error in JavaScript will report an error in typescript.
this type of check really does not know how to change it.
online and other great answers

data() {
    return {
      list: []   //
    };
},
async getList() {
  this.list = await Tanks.get();
},

clipboard.png

clipboard.png

Promise

clipboard.png

Mar.18,2022

A year later, I probably know what the reason is:

data() {
    return {
      list: []   //
    };
},

here, ts initializes an empty array of never [] type by default, which does not match the value type obtained by await Tanks.get (). It should be like this

.
data() {
    return {
      list: [] as any[]   // as Tanks.get()
    };
},

Please paste up the code. What type of this.list is it? How is the type returned by task.get declared?

generally speaking, async returns a promise, so you need to declare a Promise generic, but the return of resolve and reject may be different, you are more likely to be a joint generic, such as Promise < Object | string >, or directly any.

you provide too little information.

but I can give you an one-size-fits-all trick: ignore, is very discouraged.

/ / @ ts-ignore


if you use typescript, it is best to provide all kinds of type declarations, otherwise the type automatically inferred by the type of ts is probably not the one you want.

in addition, a mix of ts and js is highly deprecated unless you are refactoring a project.

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1b3a64a-2c218.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1b3a64a-2c218.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?