Skip to content

Commit 8d157e1

Browse files
committed
完成小节:三斜线指令
1 parent c459f50 commit 8d157e1

File tree

28 files changed

+307
-63
lines changed

28 files changed

+307
-63
lines changed

basics/declaration-files.md

Lines changed: 177 additions & 21 deletions
Large diffs are not rendered by default.

examples/declaration-files/04-declare-const-jquery/src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
declare const jQuery: (selector: string) => any;
1+
// src/index.ts
22

33
jQuery('#foo');
44
// 使用 declare const 定义的 jQuery 类型,禁止修改这个全局变量
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
// src/jQuery.d.ts
2+
3+
declare const jQuery: (selector: string) => any;

examples/declaration-files/06-declare-function/src/index.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
declare function jQuery(selector: string): any;
2-
declare function jQuery(domReadyCallback: () => any): any;
1+
// src/index.ts
32

43
jQuery('#foo');
54
jQuery(function() {
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
// src/jQuery.d.ts
2+
3+
declare function jQuery(selector: string): any;
4+
declare function jQuery(domReadyCallback: () => any): any;
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// src/Animal.d.ts
2+
3+
declare class Animal {
4+
name: string;
5+
constructor(name: string);
6+
sayHi(): string;
7+
}
Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,3 @@
1-
declare class Animal {
2-
name: string;
3-
constructor(name: string);
4-
sayHi() {
5-
return `My name is ${this.name}`;
6-
}
7-
// ERROR: An implementation cannot be declared in ambient contexts.
8-
}
1+
// src/index.ts
2+
3+
let cat = new Animal('Tom');
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// src/Directions.d.ts
2+
3+
declare enum Directions {
4+
Up,
5+
Down,
6+
Left,
7+
Right
8+
}
Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,3 @@
1-
declare enum Directions {
2-
Up,
3-
Down,
4-
Left,
5-
Right
6-
}
1+
// src/index.ts
72

83
let directions = [Directions.Up, Directions.Down, Directions.Left, Directions.Right];

0 commit comments

Comments
 (0)