1declare global {
2 interface Window {
3 FB:any;
4 }
5}
6
7let FB = window.FB; // ok now
1ts// Type definitions for [~THE LIBRARY NAME~] [~OPTIONAL VERSION NUMBER~]
2// Project: [~THE PROJECT NAME~]
3// Definitions by: [~YOUR NAME~] <[~A URL FOR YOU~]>
4
5/*~ If this library is callable (e.g. can be invoked as myLib(3)),
6 *~ include those call signatures here.
7 *~ Otherwise, delete this section.
8 */
9declare function myLib(a: string): string;
10declare function myLib(a: number): number;
11
12/*~ If you want the name of this library to be a valid type name,
13 *~ you can do so here.
14 *~
15 *~ For example, this allows us to write 'var x: myLib';
16 *~ Be sure this actually makes sense! If it doesn't, just
17 *~ delete this declaration and add types inside the namespace below.
18 */
19interface myLib {
20 name: string;
21 length: number;
22 extras?: string[];
23}
24
25/*~ If your library has properties exposed on a global variable,
26 *~ place them here.
27 *~ You should also place types (interfaces and type alias) here.
28 */
29declare namespace myLib {
30 //~ We can write 'myLib.timeout = 50;'
31 let timeout: number;
32
33 //~ We can access 'myLib.version', but not change it
34 const version: string;
35
36 //~ There's some class we can create via 'let c = new myLib.Cat(42)'
37 //~ Or reference e.g. 'function f(c: myLib.Cat) { ... }
38 class Cat {
39 constructor(n: number);
40
41 //~ We can read 'c.age' from a 'Cat' instance
42 readonly age: number;
43
44 //~ We can invoke 'c.purr()' from a 'Cat' instance
45 purr(): void;
46 }
47
48 //~ We can declare a variable as
49 //~ 'var s: myLib.CatSettings = { weight: 5, name: "Maru" };'
50 interface CatSettings {
51 weight: number;
52 name: string;
53 tailLength?: number;
54 }
55
56 //~ We can write 'const v: myLib.VetID = 42;'
57 //~ or 'const v: myLib.VetID = "bob";'
58 type VetID = string | number;
59
60 //~ We can invoke 'myLib.checkCat(c)' or 'myLib.checkCat(c, v);'
61 function checkCat(c: Cat, s?: VetID);
62}