dynamically insert either single object or array of objects breaking types

So here's 3 renditions of the same fn
const insertFighterSolo = async (fighterInsertData: FighterInsert) => {
return db.insert(fighters).values(fighterInsertData);
};

const insertFighterArray = async (fighterInsertData: FighterInsert[]) => {
return db.insert(fighters).values(fighterInsertData);
};

const insertFightersEither = async (fighterInsertData: FighterInsert | FighterInsert[]) => {
return db.insert(fighters).values(fighterInsertData);
};
const insertFighterSolo = async (fighterInsertData: FighterInsert) => {
return db.insert(fighters).values(fighterInsertData);
};

const insertFighterArray = async (fighterInsertData: FighterInsert[]) => {
return db.insert(fighters).values(fighterInsertData);
};

const insertFightersEither = async (fighterInsertData: FighterInsert | FighterInsert[]) => {
return db.insert(fighters).values(fighterInsertData);
};
Counterintuitively, the first two seem to work fine (not getting yelled at by typechecker), but the third, which I think to be entirely valid TypeScript, gives me a No overload matches this call. Overload 1 of 2,... Any idea on this? Is it something to do with the uncertain shape of the incoming parameter that it can't handle or something
0 Replies
No replies yetBe the first to reply to this messageJoin
Want results from more Discord servers?
Add your server