'I want to use superagent in TypeScript-ed React
I want to use superagent in TypeScript-ed React. I try to write Tutorial with TypeScript and try to use superagent when reqest server. And I faced errors to use superagent although I can use marked
.
When I try to use superagent like marked, request is not found.
When I try to import superagent, other files in same folder are not found.
Mmm....
My tsd.d.ts is
/// <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" />
package.json is
{
"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"
}
}
Any help please...
Solution 1:[1]
When I try to import superagent, other files in same folder are not found.
As soon as you do a module import your file becomes a module which is disconnected from the global namespace and that is a good thing.
So fix :
import * as request from "superagent";
import {CommentList} from "./commentList";
// so on
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 |