我想在 TypeScript-ed React 中使用 superagent

mor*_*ter 0 typescript reactjs

我想在 TypeScript-ed React 中使用 superagent。我尝试使用 TypeScript编写教程并尝试在请求服务器时使用超级代理。虽然我可以使用marked.

当我尝试使用标记的超级代理时,找不到请求。

在此处输入图片说明

当我尝试导入 superagent 时,找不到同一文件夹中的其他文件。

在此处输入图片说明

嗯……

我的 tsd.d.ts 是

/// <reference path="react/react.d.ts" />
/// <reference path="react/react-dom.d.ts" />
/// <reference path="node/node.d.ts" />
/// <reference path="superagent/superagent.d.ts" />
/// <reference path="marked/marked.d.ts" />
Run Code Online (Sandbox Code Playgroud)

package.json 是

{
  "name": "react-my-first",
  "version": "1.0.0",
  "scripts": {
    "tsc": "tsc",
    "tsc:w": "tsc -w",
    "lite": "lite-server",
    "start": "concurrent \"npm run tsc:w\" \"npm run lite\" "
  },
  "license": "ISC",
  "dependencies": {
    "react": "^0.14.6",
    "react-dom": "^0.14.6"
  },
  "devDependencies": {
    "concurrently": "^1.0.0",
    "lite-server": "^1.3.1",
    "typescript": "^1.7.3"
  }
}
Run Code Online (Sandbox Code Playgroud)

任何帮助请...

bas*_*rat 5

当我尝试导入 superagent 时,找不到同一文件夹中的其他文件。

只要你做一个模块导入您的文件将成为一个模块这是从全局命名空间断开,并且这是一个很好的事情

所以修复:

import * as request from "superagent";
import {CommentList} from "./commentList"; 
// so on
Run Code Online (Sandbox Code Playgroud)

更多的 :

模块:https : //basarat.gitbooks.io/typescript/content/docs/project/modules.html