koltyakov / sp-rest-proxy

🌐 SharePoint API Proxy for local development
MIT License
172 stars 43 forks source link

[ts] Could not find a declaration file for module 'sp-rest-proxy'. #57

Closed dudi44 closed 6 years ago

dudi44 commented 6 years ago

the command: npm i @types/sp-rest-proxy --save returns the following results: npm WARN notice Due to a recent security incident, all user tokens have been invalidated. Please see https://status.npmjs.org/incidents/dn7c1fgrr7ng for more details. To generate a new token, visit https://www.npmjs.com/settings/~/tokens or run "npm login". npm ERR! code E404 npm ERR! 404 Not Found: @types/sp-rest-proxy@latest

any token recreation needed by repository owner?

koltyakov commented 6 years ago

Hi @dudi44,

Thanks for posting the question.

@types/* namespace belongs to DefinitelyTyped project. It's a collection of types declaration for different popular JavaScript libraries the authors of which do not provide typings on they own. Such typings are supported with the community fellows and the declarations are usually outdated, as any changes to a library require updating and publishing typings definitions.

Libraries created using TypeScript, on the other hand, usually include types declarations together with the package itself and are always up to date.

sp-rest-proxy is written in TypeScript. But, in the early days, it was in ES6 and used module.exports which was kept for backward compatibility then migrating to TypeScript. So there is a small nuance using typings - import should be from sp-rest-proxy/dist/RestProxy to include typings:

import RestProxy, { IProxySettings } from 'sp-rest-proxy/dist/RestProxy';

const settings: IProxySettings = {
  configPath: './config/private.json'
};

const restProxy = new RestProxy(settings);
restProxy.serve();
koltyakov commented 6 years ago

Added a section in README.md.

dudi44 commented 6 years ago

Hi @koltyakov,

Thank you for very quick response!

The above workaround works fine. However I needed also run npm i @types/express --save as Could not find a declaration file for module 'express'. in .../node_modules/sp-rest-proxy/dist/interfaces/index.d.ts

so closing the issue