我有這個:
const res: any = await table.find({}).toArray();
const data: Type[] = res;
有沒有辦法做這樣的事情:
const res: Type[] = await table.find({}).toArray();
沒有錯誤:Type 'Document[]' is not assignable to type 'Type[]'.?
uj5u.com熱心網友回復:
查看型別保護和區分型別。
如果您確定res始終是 陣列Type,則可以使用as以下強制型別:
const res = await table.find({}).toArray() as Type[]; // res: Type[] now
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/369354.html
