Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

return type of Model.delete() and Model.create() is wrong. #350

Open
LoganTann opened this issue Jun 30, 2022 · 0 comments
Open

return type of Model.delete() and Model.create() is wrong. #350

LoganTann opened this issue Jun 30, 2022 · 0 comments

Comments

@LoganTann
Copy link

Similar issue to #271

Using sqlite as DBMS.

The delete() method should have a correct return type. Actually, vscode considers it returns Model | Model[]. It should return { affectedRows: number } instead.

async deleteLore(name: string): Promise<number> {
    const result = await Lore.where({ name }).delete();
    console.log(result);
    // @ts-ignore : let me compile, it works
    return result.affectedRows;
}

Without the ts-ignore :

error: TS2339 [ERROR]: Property 'affectedRows' does not exist on type 'Model | Model[]'.
  Property 'affectedRows' does not exist on type 'Model[]'.

With ts-ignore, if field exists and model name is "Lore" :

Lore { affectedRows: 0 }

By the way, other functions such as create haves the similar issue, it returns something like :

{
	"affectedRows": 1,
	"lastInsertId": 5
}

While the return type in denodb's source code (see https://doc.deno.land/https://deno.land/x/denodb@v1.0.40/mod.ts/~/Model) is Promise

Finally, I think that other methods such as select() should not return Model type, but the model's final type.

Imagine I have a model called Lore with fields title, description. When I get the result of a select, I'd like my code editor to autocomplete fields that belongs to my model. Actually, it only returns create, delete and update function.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant