You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Edited to add: Turns out this is a problem with the better-sqlite3 and @types/better-sqlite3 packages. better-sqlite3 has no typescript support and the @types package is from a different repo and is known to have such problems.
So I have a Sveltekit project running and am trying to come up to speed with typescript. But I can't figure out how to get typescript to let me use types from an installed npm package, better-sqlite3. I have both better-sqlite3 and @types/better-sqlite3 installed and in the right places in package.json.
How do I get the following to work? I took a crack at the @type comment but haven't been able to find a concise example of using them with installed NPM nodules.
/** @type {import('better-sqlite3').Database} */
import Database from 'better-sqlite3'
let db:Database = new Database('foo.db');
But LSP throws the error "Cannot use namespace 'Database' as a type."
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Edited to add: Turns out this is a problem with the better-sqlite3 and @types/better-sqlite3 packages. better-sqlite3 has no typescript support and the @types package is from a different repo and is known to have such problems.
So I have a Sveltekit project running and am trying to come up to speed with typescript. But I can't figure out how to get typescript to let me use types from an installed npm package, better-sqlite3. I have both better-sqlite3 and @types/better-sqlite3 installed and in the right places in package.json.
How do I get the following to work? I took a crack at the
@type
comment but haven't been able to find a concise example of using them with installed NPM nodules.But LSP throws the error "Cannot use namespace 'Database' as a type."
Beta Was this translation helpful? Give feedback.
All reactions