typescript - 錯誤 TS2322:類型 'DeepPartial[]' 無法分配給類型 'T[]'
以下 TypeScript 代碼
import { Repository } from 'typeorm'
const save = async <T>(repo: Repository<T>, entities: T[]): Promise<T[]> => {
return await repo.save(map((entity) => omit(['createdAt', 'updatedAt'], entity))(entities))
}
產生以下錯誤
src/database/dao/user/user.dao.ts:46:3 - error TS2322: Type 'DeepPartial<T>[]' is not assignable to type 'T[]'.
Type 'DeepPartial<T>' is not assignable to type 'T'.
'T' could be instantiated with an arbitrary type which could be unrelated to 'DeepPartial<T>'.
- TypeScript: 4.7.3
- typeorm: 0.2.45
我對 TypeScript 和 TypeORM 還很陌生,任何幫助都很感激。