问题
I want to create an server side script, for this I require "Q", so I include the q.d.ts file. And I use this to import q:
var Q = require("q");
Now I recive this error: Duplicate identifier 'Q'
Does somebody know how to solve this name conflict?
The complete startup script:+
///<reference path="Scripts/typings/q/Q.d.ts" />
///<reference path="Server.ts" />
///<reference path="Services/DatabaseProvider.ts" />
///<reference path="Response/Response.ts" />
///<reference path="Response/DataResponse.ts" />
var Q = require("q");
var di = require("ng-di");
var app = di.module("App", []);
app.service("server", Server);
app.service("$databaseProvider", DatabaseProvider);
app.run((server: Server) => {
server.run();
});
di.injector(["App"]);
回答1:
Duplicate identifier 'Q'
In the absence of an import
or an export
statement at the root of your file: Your file as well as any other such file passed to the TypeScript compiler is considered a part of the global namespace. So the variable Q
is conflicting with the one declared in q.d.ts
.
Fix
import
Q, don't just require
it :
import Q = require("q");
More about External modules : https://www.youtube.com/watch?v=KDrWLMUY0R0
来源:https://stackoverflow.com/questions/29050092/node-js-with-typescript-require-and-d-ts-files