我有一个角色1.5项目,我正在慢慢转换为打字稿。我还没有提交模块,我只是从其他文件导入接口,而不是创建模块。我现在有许多打字稿文件,并且该项目已经使用打字稿版本2.1.5编译得很好。在我将我的npm typescript包升级到2.2.0或2.2.1之后,我从tsc得到错误,“错误TS2503:在某些行上找不到使用”angular“的命名空间'angular'”。我正在使用命令行直接执行tsc。
我试过在我的tsconfig中添加“moduleResolution”:“Node”,但没有用。
我可以使用import * as angular from "../../../node_modules/@types/angular/index";
使构建工作正常,但是,由于模块已经创建,我得到运行时错误,我们的项目尚不支持。
tsconfig.json
{
"compileOnSave": true,
"compilerOptions": {
"module": "commonjs",
"noImplicitAny": true,
"removeComments": false,
"preserveConstEnums": true,
"target": "es5",
"sourceMap": true,
"listFiles": false,
"allowJs": true,
"outDir": "js/app"
},
"include": [ "app/**/*", "@types/**/*" ],
"exclude": [ "node_modules" ]
}
的package.json
{
"name": "Imagine.UI.NG",
"version": "0.0.0",
"devDependencies": {
"@types/angular": "^1.6.7",
"@types/angular-mocks": "^1.5.9",
"@types/angular-ui-bootstrap": "^0.13.39",
"@types/jasmine": "^2.5.41",
....
"typescript": "^2.1.5"
},
"dependencies": {
"angular-breadcrumb": "^0.5.0",
"angular-ui-router": "^0.4.2",
"karma-sinon": "^1.0.5",
"karma-trx-reporter": "^0.2.9"
}
}
在public $http: angular.IHttpService
行上出现“错误TS2503:找不到命名空间'angular'”的示例代码失败。它没有抱怨angular.module
。
import { IImagineSettings } from "../../app.config";
class AboutCtrl {
SiteVersion: string;
ApiVersion: string;
static $inject = ["imagineSettings", "$http", "$translate"];
constructor(public imagineSettings: IImagineSettings, public $http: angular.IHttpService, public $translate: any) {
let fake = "do something";
}
}
angular.module("Imagine.UI.NG")
.component("about",
{
templateUrl: "app/partial/about/about.html",
bindings: {},
controller: AboutCtrl
});