我试图使用Angular 1.x与新的TS2和@types注册表,但遇到问题.看起来@types没有使用打字注册表所称的"全局"类型.我遇到以下错误:
error TS2686: 'angular' refers to a UMD global, but the current file is a module. Consider adding an import instead.
Run Code Online (Sandbox Code Playgroud)
角度代码如下:
import "angular";
import "angular-route";
const app = angular.module("charter-app", ["ui.bootstrap", "ui.router", "templates", "charter-app.controllers"]);
Run Code Online (Sandbox Code Playgroud)
tsconfig.json:
{
"compilerOptions": {
"declaration": false,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"mapRoot": "./",
"module": "system",
"moduleResolution": "node",
"sourceMap": true,
"target": "es5",
"inlineSources": true,
"removeComments": false,
"noImplicitAny": false,
"typeRoots": [ "node_modules/@types/" ],
"types": [ "angular", "angular-ui-bootstrap", "angular-ui-router" ],
"outFile": "app.js"
}
}
Run Code Online (Sandbox Code Playgroud)
试着使用以下内容
"devDependencies": {
"@types/angular": "^1.5.20", …Run Code Online (Sandbox Code Playgroud)