-
Notifications
You must be signed in to change notification settings - Fork 2.6k
/
Copy pathdeclarationspace.ts
67 lines (54 loc) · 1.19 KB
/
declarationspace.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
export module first {
class Foo { }
interface Bar { }
type Bas = {}
var foo: Foo;
var bar: Bar;
var bas: Bas;
}
namespace second {
interface Bar { };
var bar = Bar; // ERROR: "cannot find name 'Bar'"
}
namespace third {
class Foo { }
var someVar = Foo;
var someOtherVar = 123;
}
namespace fourn {
var foo = 123;
var bar: foo; // ERROR: "cannot find name 'foo'"
}
namespace meh {
var something = {};
// (function(something) {
// something.foo = 123;
// })(something || something = {})
}
namespace utility {
export function log(msg) {
console.log(msg);
}
export function error(msg) {
console.error(msg);
}
}
// usage
utility.log('Call me');
utility.error('maybe!');
module importing {
class Foo { }
var Bar = Foo;
var bar: Bar; // ERROR: "cannot find name 'Bar'"
}
namespace importing {
export class Foo { }
}
import Bar = importing.Foo;
var bar: Bar; // Okay
namespace typeofAnnotation {
var foo = 123;
var bar: typeof foo; // `bar` has the same type as `foo` (here `number`)
bar = 456; // Okay
bar = '789'; // ERROR: Type `string` is not `assignable` to type `number`
}