dyedgreen / deno-sqlite

Deno SQLite module
https://deno.land/x/sqlite
MIT License
409 stars 36 forks source link

TypeScript compiler flags error for query method on VS Code - ts(2554) #58

Closed Coteh closed 4 years ago

Coteh commented 4 years ago

Description

Originally filed as PR #56 since I mistakenly assumed that the query method won't accept just one argument, but this is not the case. Seems like this is an error with the typing definition for this method.

Expected Behaviour

When I call query method with just the query string, there should be no TypeScript error.

Actual Behaviour

Expected 2 arguments, but got 1. ts(2554)
<long hash that I assume resolves to file with query method>(110, 14): An argument for 'values' was not provided.

However, if you execute it with deno run it'll still compile and run successfully.

Reproduction Steps

Open up Visual Studio Code in a new folder, create a TypeScript file (doesn't matter the name). Simply copy and paste the README example into it. :)

import { open, save } from "https://deno.land/x/sqlite/mod.ts";

// Open a database
const db = await open("test.db");
db.query("CREATE TABLE IF NOT EXISTS people (id INTEGER PRIMARY KEY AUTOINCREMENT, name TEXT)");

const names = ["Peter Parker", "Clark Kent", "Bruce Wayne"];

// Run a simple query
for (const name of names)
  db.query("INSERT INTO people (name) VALUES (?)", [name]);

// Print out data in table
for (const [name] of db.query("SELECT name FROM people"))
  console.log(name);

// Save and close connection
await save(db);
db.close();

Also have the Deno VS Code extension installed and ensure it's enabled on your project by putting this in either workspace or user settings.json:

{
    "deno.enable": true
}
dyedgreen commented 4 years ago

Can you check if the error persists with https://github.com/dyedgreen/deno-sqlite/pull/57

Coteh commented 4 years ago

Just checked out #57 branch, subbed out open and save with new DB and db.close() respectively (due to API changes in that PR) and looks like no TypeScript error present. Feel free to close. :)

dyedgreen commented 4 years ago

Great! (Btw, you don't need to explicitly close to safe the changes to disk, the new branch will commit the changes as you run the queries, like you'd expect from a regular SQLite 😄)