sebelga / gstore-node

Google Datastore Entities Modeling for Node.js
Apache License 2.0
292 stars 53 forks source link

tsc error: Could not find a declaration file for module 'nsql-cache' #223

Open reedom opened 4 years ago

reedom commented 4 years ago

When I invoke tsc upon my project, I got the following error in node_modules/gstore-node/lib/index, due to lack of nsql-cache module's type definition. How other people overcome this?

 error TS7016: Could not find a declaration file for module 'nsql-cache'. '/path/to/myproj/node_modules/nsql-cache/index.js' implicitly has an 'any' type.
  Try `npm install @types/nsql-cache` if it exists or add a new declaration (.d.ts) file containing `declare module 'nsql-cache';`

1 import NsqlCache, { NsqlCacheConfig } from 'nsql-cache';
                                             ~~~~~~~~~~~~

As workarounds, I could take the ways below, but I feel like none of them are best. a. turn off strict flag in tsconfig.json b. include sql-cache's type definition in gstore-node repository somehow

sebelga commented 4 years ago

Hi @reedom, sorry for the late answer!

Have you tried copying the declaration in your project from the repo: https://github.com/sebelga/gstore-node/blob/master/typings/nsql-cache/index.d.ts

Cheers! 👍

reedom commented 4 years ago

Yes, I had tried and then posted this issue, while wondering it was whether the expected solution or just a workaround, or even it was only me who face this kind of type-not-found error.

And my question hasn't changed ever since.

sebelga commented 4 years ago

Hello,

So indeed you need to copy the nsql-cache typing from this repo into yours.

I added a "typings" folder at the root with this folder structure

- typings
  - nsql-cache
    - index.d.ts

Then in you tsconfig.json file you need to add this folder

// tsconfig.json
{
  "compilerOptions": {
    ...
  },
  "include": [
    "src",
    "typings"
  ]
}

Let me know if it works for you.