-
Notifications
You must be signed in to change notification settings - Fork 53
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
Missing typing for sqlite3Worker1Promiser #53
Comments
Hey there! Firstly, thanks for shipping this package in the first place! :) I understand that having this typed as "any" is far from ideal, and even saw the ongoing PR to add the type definitions to it. Not an easy job! However, it would make a potential developer less confused when using the package with Typescript if the type was shipped by default instead of having to declare it manually. Especially since the recommended approach uses "sqlite3Worker1Promiser". Maybe we could add a JSDoc noting that the type is under development and keep it as something along the lines of: (...args: unknown[]) => Promise<unknown> I know there's nothing more permanent than a temporary solution, so I understand if we don't follow with this approach too 😅 |
@filipe-freire I'm not opposed, but am unsure where you'd add this, the caveat from #53 (comment) still applies 🫣. To the thin wrapper code part of this repo (if so, please file a quick PR), or the underlying SQLite code (if so, that's something to raise with @sgbeal)? |
In the upstream project we use only vanilla JS and avoid all tooling-specific extensions (because none of us use them, so we can't be relied upon to maintain such pieces properly long-term). |
Never mind my comment above, after analyzing the PR more thoroughly the work there is already way beyond what I suggested. Apologies for that 😅 The work would be done in this wrapper though. I unfortunately don't have the insight needed to complete that PR. However, an option is to merge it as it stands right now, which would still provide a better DX to someone just starting out. The only thing needed would be to change the Docs to reflect the types added: import {
sqlite3Worker1Promiser,
type Promiser,
type PromiserResponseSuccess
} from '@sqlite.org/sqlite-wasm';
const log = console.log;
const error = console.error;
const initializeSQLite = async () => {
try {
log('Loading and initializing SQLite3 module...');
const promiser = (await new Promise((resolve) => {
const _promiser = sqlite3Worker1Promiser({
onready: () => resolve(_promiser)
});
})) satisfies Promiser;
log('Done initializing. Running demo...');
const configResponse = (await promiser(
'config-get', {}
)) as PromiserResponseSuccess<'config-get'>;
log('Running SQLite3 version', configResponse.result.version.libVersion);
const openResponse = (await promiser('open', {
filename: 'file:mydb.sqlite3?vfs=opfs'
})) as PromiserResponseSuccess<'open' >;
const {
dbId
} = openResponse;
log(
'OPFS is available, created persisted database at',
openResponse.result.filename.replace(/^file:(.*?)\?vfs=opfs$/, '$1')
);
// Your SQLite code here.
} catch (err) {
if (!(err instanceof Error)) {
err = new Error(err.result.message);
}
error(err.name, err.message);
}
};
initializeSQLite(); Type casting is not an ideal solution, yet it might be a good enough compromise while this work is ongoing. I'll defer the decision to you! ✌🏻 |
I don't know how merge-ready #54 is. Do people here generally approve of a not-perfect-but-good-enough merger? I think for the documentation, we should keep it vanilla. Those wanting to use the types will know how to include them, whereas people unfamiliar with TypeScript might be wondering what the to them weird |
How about simply adding a Typescript version for its users out there? Having them figure it out by themselves is not the best solution here imo... As for the approval of "not-perfect-but-good-enough" PR's, I'll defer that to y'all 😁 |
Any update on this? I cannot follow the recommended "wrapped worker" approach in my Vite React + TypeScript project due to |
In order to follow the recommended "wrapped worker" approach from the readme I had to add:
immediately below the import statement, because
sqlite3Worker1Promiser
is not included in theindex.d.ts
The text was updated successfully, but these errors were encountered: