m4heshd / better-sqlite3-multiple-ciphers

better-sqlite3 with multiple-cipher encryption support 🔒
MIT License
140 stars 27 forks source link

Could not find a declaration file for module 'better-sqlite3-multiple-ciphers' node_modules/better-sqlite3-multiple-ciphers/lib/index.js' implicitly has an 'any' type #22

Closed raphael10-collab closed 2 years ago

raphael10-collab commented 2 years ago

import Database from 'better-sqlite3-multiple-ciphers' :

ERROR in src/main/index.ts:131:22
TS7016: Could not find a declaration file for module 'better-sqlite3-multiple-ciphers'. '/home/raphy/Playground/node_modules/better-sqlite3-multiple-ciphers/lib/index.js' implicitly has an 'any' type.
  Try `npm i --save-dev @types/better-sqlite3-multiple-ciphers` if it exists or add a new declaration (.d.ts) file containing `declare module 'better-sqlite3-multiple-ciphers';`
    129 | //const infopiecesDb = new Database(infopiecesDbpath, { verbose: console.log })
    130 |
  > 131 | import Database from 'better-sqlite3-multiple-ciphers'

"@types/better-sqlite3": "^7.5.0",
"better-sqlite3": "^7.5.3",
"better-sqlite3-multiple-ciphers": "^7.5.2",
"electron": "17"
 node:  v16.15.0

I added in src/type/type.d.ts :

export {}

declare global {
  declare module 'better-sqlite3-multiple-ciphers
}

but still get the same error.

Is there any @types/better-sqlite3-multiple-ciphers ?

m4heshd commented 2 years ago

Is there any @types/better-sqlite3-multiple-ciphers ?

Unfortunately I haven't had the time to do a PR for that. I'd love some help with this. Since the API is completely identical to better-sqlite3, all somebody will have to do is create a fork of @types/better-sqlite3, rename it to better-sqlite3-multiple-ciphers and just deal with the PR process of DefinitelyTyped.

raphael10-collab commented 2 years ago

@m4heshd I discovered that require('better-sqlite3-multiple-ciphers')(infopiecesDbpath, { verbose: console.log }) doesn't anymore complain about any missing declaration file for 'any' type

In the meanwhile I get this other error: SqliteError: file is not a database: https://github.com/m4heshd/better-sqlite3-multiple-ciphers/issues/23

jasonk commented 2 years ago

Since the API is identical you don't even have to go to the trouble of copying the types. You can just add @types/better-sqlite3 as a devDependency and then add a types file like this:

declare module 'better-sqlite3-multiple-ciphers' {
  import { BetterSqlite3 } from 'better-sqlite3';
  export default BetterSqlite3.DatabaseConstructor;
}

You also don't have to deal with the PR process of DefinitelyTyped, you can include the types in your own repo and publish them along with the library (which is the preferred method anyway, since you don't have to install a separate types library).

(Edit to clarify): Anybody using this library and wishing they had types can use the snippet above in a *.d.ts file to get them. To add types to this repo all you need is something like "types": "index.d.ts" in package.json, adding @types/better-sqlite3 to devDependencies, and then put this into index.d.ts:

import BetterSqlite3 from 'better-sqlite3';
export = BetterSqlite3;