关于javascript:Typescript – 内部模块中的import声明不能引用外部模块

Typescript - import declarations in an internal module cannot reference an external module

而在实践typescript vscode,待办事项应用N的发展,进出口的"待办事项"模块,vscode IntelliSense哪里错误:进口声明模块在内部无法参考外部模块因此,在控制台类型的错误:"todoapp所以没有定义"

任何人可以帮助我吗?我presume斜面结构是不正确的,但它似乎正确。我有我的目标是所有编译。TS文件,最好是到另一个js文件"testapp.js"。

我heres代码:

task.ts

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
module TodoApp {

    export enum TaskType { FrontEnd, BackEnd, Designer };

    interface Itask {
        Name: string;
        Description: string;
        TaskType: TaskType;
        Completed: boolean;
    }

    export class Task implements Itask {
        Name: string;
        Description: string;
        Completed: boolean = false;
        TaskType: TaskType;

        constructor(Name: string, Description: string, TaskType: TaskType) {
            this.Name = Name;
            this.Description = Description;
            this.TaskType = TaskType;
        }

    }

}

todo.ts

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
    ///<reference path="task.ts" />
///<reference path="../typings/jquery/jquery.d.ts" />

module TodoApp {
   "use strict"

    interface IJson {

    }

    interface ITaskManager {
        Tasks: Task[];
        GetTasks(t: any[]): void;
        AddTask(t: Task): void;
        UpdateTask(n: string, d: string, tt: TaskType): void;
        DeleteTask: {
            (i: number): void;
            (i: Task): void;
        }
    }

    export class TaskManager implements ITaskManager {

        public Tasks = new Array<Task>();

        constructor() {

        }

        GetTasks(d: any[]) {
        }

        public AddTask(_task: Task) {
            this.Tasks.push(_task);
        }

        UpdateTask(_name: string, _desc: string, _taskType: TaskType) {
        }

        DeleteTask(i: any) {
            if (typeof i === typeof Task) {
                //delete object

            } else {
                //delete task of index

            }
        }

    }
}

testapp.ts

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
module TestApp {

    import TodoApp = require("todo"); ///<< error occurs here

    export class ControlTodoApp {

        static Start() {

            window.onload = function(e) {
                var tm = new TodoApp.TaskManager();
                var task = new TodoApp.Task("MyTask","Task Description", TodoApp.TaskType.Designer);
                tm.AddTask(task);

                console.log(tm.Tasks);
            }

        }
    }
}



var ca = new TestApp.ControlTodoApp.Start();

index.html

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
<!DOCTYPE html>
<html lang="en">
<head>


</head>

<body>
 
   
       
            <img src="assets/images/myimg.png" alt="my img" />
       
   
   


<script src="assets/js/default/jquery.min.js">
<script src="assets/js/ts/testApp.js">
</body>
</html>

在代码中组合commonjs和amd,使用其中一个

测试程序TS

1
2
///<reference path="task.ts" />
///<reference path="todo.ts" />

测试程序TS

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
module TestApp {
    import TaskManager = require("todo");
    import TaskType = require("task");

    export class ControlTodoApp {
        static Start() {

            window.onload = function(e) {
                var tm = new TaskManager.TaskManager();
                var task = new TaskType.Task("MyTask","Task Description", TaskType.TaskType.Designer);
                tm.AddTask(task);

                console.log(tm.Tasks);
            }
        }
    }
}

任务.ts

1
2
3
4
export = TodoApp;
module TodoApp {
    ...
}

托多TS

1
2
3
4
export = TodoApp;
module TodoApp {
    ...
}