dyedgreen / deno-sqlite

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

Export SqliteError as value #156

Closed jsejcksn closed 2 years ago

jsejcksn commented 2 years ago

Currently, a compiler error is produced when trying to use SqliteError as a value:

'SqliteError' cannot be used as a value because it was exported using 'export type'.deno-ts(1362)

It is useful to provide the export as a value for cases like the following:

import {DB, SqliteError} from 'https://deno.land/x/sqlite/mod.ts';

/*...*/

try {
  db.query(/*...*/); // or any other import that might throw an instance of `SqliteError`
}
catch (ex) {
  if (ex instanceof SqliteError) {
    // handle SQLite error
  }
  else { /*...*/ }
}

This PR exports the class as a value to address this. (It can, of course, still be used as a type.)

dyedgreen commented 2 years ago

I was under the impression that that was already possible with typescript, but it makes sense that it wouldn’t be 😅

Looks good to me though 😊

jsejcksn commented 2 years ago

Thanks. The reason for that is type-only imports and exports are elided by default (and therefore not available) in the compiled JavaScript.

Will this be released soon (and become available on deno.land/x), or should I just use the latest wasm build commit branch in my imports?

import {SqliteError} from 'https://raw.githubusercontent.com/dyedgreen/deno-sqlite/f3662458ed7415681144b04a828ff6bb0194ee45/mod.ts';
dyedgreen commented 2 years ago

I'm happy to make a point release 😅

jsejcksn commented 2 years ago

I see it — thanks!