简体   繁体   English

当使用用于打字稿的ui-router类型定义时,模块'ng'没有导出的成员'ui'

[英]module 'ng' has no exported member 'ui' when using ui-router type definition for typescript

I am trying to use this typescript definition file for ui-router : 我想为ui-router使用这个打字稿定义文件:

https://github.com/borisyankov/DefinitelyTyped/blob/master/angular-ui/angular-ui-router.d.ts https://github.com/borisyankov/DefinitelyTyped/blob/master/angular-ui/angular-ui-router.d.ts

Here is the code at the top of the definition file: 以下是定义文件顶部的代码:

// Type definitions for Angular JS 1.1.5+ (ui.router module)
// Project: https://github.com/angular-ui/ui-router
// Definitions by: Michel Salib <https://github.com/michelsalib>
// Definitions: https://github.com/borisyankov/DefinitelyTyped

/// <reference path="../angularjs/angular.d.ts" />

declare module ng.ui {

    interface IState {
    ...

Here is how I am using it: 这是我如何使用它:

module MyModule
{
    export class MyStateConfig
    {
        constructor(
            //                     -> error on the word ng.ui on next line
            private $stateProvider: ng.ui.IStateProvider, 
            private $urlRouterProvider: ng.ui.IUrlRouterProvider
            ...)
        {
            this.$stateProvider.state(...

This was working in Visual Studio but now with WebStorm I get a message saying " 这是在Visual Studio中工作但现在使用WebStorm我得到一条消息说“

module 'ng' has no exported member 'ui' 模块'ng'没有导出成员'ui'

Can someone give me advice on this. 有人可以给我这方面的建议。 Is this something to do with a different module system with WebStorm? 这与使用WebStorm的不同模块系统有关吗?

Have you tried adding a reference comment in your module source file? 您是否尝试在模块源文件中添加引用注释? Something like... 就像是...

/// <reference path="path/to/angular-ui/angular-ui-router.d.ts" />

Visual Studio doesn't require this because its msbuild tasks automatically tell the compiler to reference any definition that are included in the project. Visual Studio不需要这个,因为它的msbuild任务会自动告诉编译器引用项目中包含的任何定义。 I'm guessing WebStorm doesn't use msbuild project files. 我猜测WebStorm不使用msbuild项目文件。

  1. Ensure the @types/angular-ui-bootstrap npm package is installed. 确保安装了@ types / angular-ui-bootstrap npm包。

    npm install @types/angular-ui-bootstrap

  2. Check your tsConfig.json file, in compilerOptions , look for a types array. 检查tsConfig.json文件,在compilerOptions中查找types数组。 Try removing types or replacing with typeRoots . 尝试删除types或替换typeRoots Something like this: 像这样的东西:

    "compilerOptions": { "target": "ES5", "sourceMap": true, .... .... "typeRoots": [ "node_modules/@types" ] },

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM