VS Code 中用于 NodeJS OAuth 库的 IntelliSense

IntelliSense for NodeJS OAuth library in VS Code

第一次使用 VS 代码并尝试让 IntelliSense 工作。

这是我所做的:

使用 VS 代码创建并打开一个目录。

添加文件 package.json,内容为:

{
  "name": "MyApp",
  "version": "0.0.0",
  "private": true,
  "dependencies": {
    "oauth": "^0.9.13"
  }
}

npm install 检索 oauth 库

添加文件 app.js 内容(示例代码):

/// <reference path='node_modules/oauth/lib/oauth.js' />
/// <reference path='node_modules/oauth/lib/oauth2.js' />

var OAuth = require('oauth');

var OAuth2 = OAuth.OAuth2;    
var key = 'your key';
var secret = 'your secret';
var oauth2 = new OAuth2(
  key,
  secret, 
  'https://api.twitter.com/', 
  null,
  'oauth2/token', 
  null);

oauth2.getOAuthAccessToken(
  '',
  {'grant_type':'client_credentials'},
  function (e, access_token, refresh_token, results){
    console.log('bearer: ', access_token);
  });

不幸的是,我没有为 oauth 库获得任何 IntelliSense。当我输入 console. 时,我确实得到了它。我有什么遗漏或做错了什么吗?

谢谢!

VS Code 即使 JavaScript 也使用 TypeScript 定义文件。尝试添加 oauth.js.d.ts to you project. Either use a ///-reference or create a jsconfig.json-file to mark a project: JS in VS Code