-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
575 lines (512 loc) · 17.3 KB
/
index.html
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>TypeScript - The Good Parts</title>
<meta name="description" content="An overview of the features in TypeScript">
<meta name="author" content="Jeremy Mason">
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-status-bar-style" content="black-translucent">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
<link rel="stylesheet" href="css/reveal.min.css">
<link rel="stylesheet" href="css/theme/default.css" id="theme">
<link rel="stylesheet" href="css/custom.css"><!-- For syntax highlighting -->
<link rel="stylesheet" href="lib/css/zenburn.css"><!-- If the query includes 'print-pdf', use the PDF print sheet -->
<script type="text/javascript">
document.write( '<link rel="stylesheet" href="css/print/' + ( window.location.search.match( /print-pdf/gi ) ? 'pdf' : 'paper' ) + '.css" type="text/css" media="print">' );
</script><!--[if lt IE 9]>
<script src="lib/js/html5shiv.js"></script>
<![endif]-->
</head>
<body>
<div class="reveal">
<div class="slides">
<section>
<section>
<h1>TypeScript</h1>
<h2>The Good Parts</h2>
<p>by Jeremy Mason</p><br>
<div class="break">
<h3>Download the slides</h3><a href="https://github.com/jeremyalan/TypeScript-TheGoodParts">https://github.com/jeremyalan/TypeScript-TheGoodParts</a>
</div>
<div class="break">
<h3>Contact me</h3>
<div><span>@jeremyalan</span><br><span>[email protected]</span></div>
</div>
</section>
<section>
<h2>Sponsors</h2><img src="slides/images/sponsors.png" height="60%">
</section>
<section>
<h1>Quick Poll</h1>
</section>
</section>
<section>
<section>
<h2>What is TypeScript?</h2>
<p><span>TypeScript is a programming language</span><br><span class="small"> <span>(Full spec available at </span><a href="http://www.typescriptlang.org">typescriptlang.org</a><span>)</span></span></p>
<p class="break"><span>Superset of Javascript</span><br><span class="small">(pure JS is valid TypeScript)</span></p>
<p class="break">Transcompiles into pure Javascript</p>
</section>
<section>
<h2>What is TypeScript</h2>
<div>
<p>Offers other language features</p>
<ul>
<li>Modules (Namespaces)</li>
<li>Types + inheritance</li>
<li>Inline functions</li>
<li>many more...</li>
</ul>
</div>
</section>
<section>
<h2>What isn't TypeScript</h2>
<h3>C++ | C# | Java</h3>
<p>Transcompiling to Javascript from existing languages is difficult because they have different design principles</p>
<p class="break">TypeScript is a whole new language designed to harness the implicit power of Javascript</p>
</section>
<section>
<h2>What isn't TypeScript</h2>
<h3>CoffeeScript</h3>
<p> <span>CoffeeScript provides a way to be more expressive</span><br><span>In other words, do more with less code</span></p>
<p><span>TypeScript is more verbose but provides type safety</span></p>
</section>
<section>
<h2>What isn't TypeScript</h2>
<h3>Backbone, Knockout, Angular, ...</h3>
<p><span>TypeScript is just a language</span><br><span>It's not a framework for building applications</span></p>
<p><span>It is possible to build web applications with TypeScript using any existing framework</span></p>
</section>
</section>
<section>
<section>
<h2>Classes</h2>
<h3>Simple example</h3>
<pre>class Person {
FirstName: string;
LastName: string;
constructor(firstName: string, lastName: string) {
this.FirstName = firstName;
this.LastName = lastName;
}
getFullName() {
return this.FirstName + ' ' + this.LastName;
}
}
...
var person = new Person('Tom', 'Smith');
console.log(person.getFullName()); // 'Tom Smith'</pre>
</section>
<section>
<h2>Classes</h2>
<h3>Private variables</h3>
<pre>class Person {
private FirstName: string;
private LastName: string;
constructor(firstName: string, lastName: string) {
this.FirstName = firstName;
this.LastName = lastName;
}
getFullName() {
return this.FirstName + ' ' + this.LastName;
}
}
var person = new Person('Tom', 'Smith');
// OK
console.log(person.getFullName());
// ERROR!!
console.log(person.FirstName); </pre>
</section>
<section>
<h2>Classes</h2>
<h3>Private variables</h3><br>
<div class="strong underline">A brief note on using private</div><br>
<div>Javascript does not understand public/private. Private scope is only enforced by the TypeScript compiler</div>
</section>
<section>
<h2>Classes</h2>
<h3>Static variables</h3>
<pre>class Logger {
static Instance = new Logger();
constructor() {
}
write(message: string) {
console.log(message);
}
}
// Sample usage
Logger.Instance.write('Hello, world!');</pre>
</section>
<section>
<h2>Classes</h2>
<h3>Inheritance</h3>
<div>
<pre>class Employee extends Person {
Title: string;
constructor(first: string, last: string, title: string) {
super(first, last);
this.Title = title;
}
getFullName() {
return super.getFullName() + ', ' + this.Title;
}
}
...
var employee = new Employee('Tom', 'Smith', 'VP of Engineering');
// 'Tom Smith, VP of Engineering'
console.log(employee.getFullName());</pre>
</div>
</section>
</section>
<section>
<section>
<h2>Interfaces</h2>
<h3>Simple example</h3>
<pre>interface IPerson {
FirstName: string;
LastName: string;
getFullName: () => string;
}
class Person implements IPerson {
FirstName: string;
LastName: string;
constructor(firstName: string, lastName: string) {
this.FirstName = firstName;
this.LastName = lastName;
}
getFullName() {
return this.FirstName + ' ' + this.LastName;
}
}</pre>
</section>
<section>
<h2>Interfaces</h2>
<h3>3rd Party Libraries</h3>
<pre>declare var $: (selector: string) => any;
interface JQuerySpin {
spin: () => void;
}
(<JQuerySpin>$('#spinner')).spin();</pre>
</section>
<section>
<h2>Interfaces</h2>
<h3>3rd Party Libraries</h3><br>
<div class="strong underline">A brief note on 3rd party interfaces</div><br>
<div>Interface definitions files end in .d.ts, meaning it is only used by the compiler (no compiled output).</div><br>
<div>DefinitelyTyped is a project on GitHub that provides interface definitions for common libraries.</div>
<div><a href="https://github.com/borisyankov/DefinitelyTyped">https://github.com/borisyankov/DefinitelyTyped</a></div>
</section>
<section>
<h2>Interfaces</h2>
<h3>Method overloading</h3>
<div>Supported by interfaces, not by classes</div>
<div class="small">
<pre>interface Greeter {
sayHello(): void;
sayHello(name: string): void;
}
class ConsoleGreeter implements Greeter {
sayHello(name) {
if (name) {
console.log('Hello, ' + name + '!');
}
else {
console.log('Hey you!');
}
}
}
var greeter = new ConsoleGreeter();
greeter.sayHello(); // Hey you!
greeter.sayHello('Tom'); // Hello, Tom!</pre>
</div>
</section>
</section>
<section>
<section>
<h2>Type Annotations</h2>
<h3>Basic Types</h3>
<ul>
<li>number</li>
<li>string</li>
<li>Function</li>
<li>Custom Types (classes, interfaces, etc.)</li>
<li>Special type: any</li>
</ul>
</section>
<section>
<h2>Type Annotations</h2>
<h3>Basic Types</h3><strong class="small text-left">Variables</strong>
<pre>var x: string = 'Hello, world!';
</pre><strong class="small text-left">Function arguments, return values</strong>
<pre>function sum(x: number, y: number): number {
return x + y;
}
</pre><strong class="small text-left">Function types</strong>
<pre>var sum: (x: number, y: number) => number;
sum = function (x, y) {
return x + y;
}</pre>
</section>
<section>
<h2>Type Annotations</h2>
<h3>Lookup Types</h3>
<div>TypeScript supports key/value maps</div><br>
<pre>interface Person {
Name: string;
}
var personsById: {
[id: string]: Person;
}
var person = personsById['user'];
console.log(person.Name);</pre>
</section>
</section>
<section>
<section>
<h2>Functions</h2>
<h3>Default parameters</h3>
<pre>class Person {
Name: string;
Title: string;
constructor(name: string, title: string = 'Mr.') {
this.Name = name;
this.Title = title;
}
getFullName() {
return this.Title + ' ' + this.Name;
}
}
var person1 = new Person('Tom Smith');
var person2 = new Person('Susie Johnson', 'Ms.');
console.log(person1.getFullName()); // 'Mr. Tom Smith'
console.log(person2.getFullName()); // 'Ms. Susie Johnson'</pre>
</section>
<section>
<h2>Functions</h2>
<h3>Splats</h3>
<pre>function format(fmt: string, ...args: any[]) {
var result = fmt;
for (var i = 0; i < args.length; i++) {
result = result.replace('{' + i + '}', args[i]);
}
return result;
}
// Hello, Susie and Jim
console.log(format('Hello, {0} and {1}!', 'Susie', 'Jim'));</pre>
</section>
<section>
<h2>Functions</h2>
<h3>Inline Functions</h3>
<div>(also called Lambda expressions)</div>
<pre>var items = [
{ Name: 'Susie', Age: 27 },
{ Name: 'Jim', Age: 34 }
];
var result = _.find(items, a => a.Name == 'Jim');
// Multiple parameters
var sum = (a, b) => a + b;
// Multi-line
var abs = (a) => {
if (a < 0) {
return -a;
}
return a;
}</pre>
</section>
<section>
<h2>Functions</h2>
<h3>Inline functions</h3>
<div>Inline functions will inherit 'this' context.</div>
<pre>class Model {
person: Person;
theHardWay() {
var that = this;
$.ajax(...).done(function (data) {
that.person = data;
}
}
theEasyWay() {
$.ajax(...).done(data => this.person = data);
}
}</pre>
</section>
</section>
<section>
<section>
<h2>Modules</h2>
<h3>Simple example</h3>
<pre>module App.Views {
export class MainView {
private model: any;
constructor(model) {
this.model = model;
}
render() {
...
}
}
}
var model = {};
var view = App.Views.MainView(model);
view.render();</pre>
</section>
<section>
<h2>Modules</h2>
<h3>Public and Private Scope</h3>
<pre>module App.Views {
class PrivateView {
...
}
export class PublicView {
...
}
}
// OK
var public = new App.Views.PublicView();
// Error!
var private = new App.Views.PrivateView();</pre>
</section>
<section>
<h2>Modules</h2>
<h3>External References</h3>
<pre>/// <reference path="../../lib/jquery.d.ts" />
module App.Models {
export class MainModel {
data: any;
init() {
// $ is defined in jquery.d.ts
$.ajax(...).done(data => this.data = data);
}
}
}</pre>
</section>
</section>
<section>
<section>
<h2>Tools</h2>
<h3>Web Playground</h3>
<div> <a href="http://www.typescriptlang.org/Playground">http://www.typescriptlang.org/Playground</a></div>
<div class="break">
<ul>
<li>Great for getting started</li>
<li>View compiler errors</li>
<li>Basic Intellisense support</li>
</ul>
</div>
</section>
<section>
<h2>Tools</h2>
<h3>Command-Line Compiler</h3>
<div class="small break">
<ul>
<li>Available via NPM
<pre>> npm install -g typescript</pre>
</li>
<li>Compile
<pre>> tsc app.ts</pre>
</li>
<li>File watcher also available
<pre>> tsc -w</pre>
</li>
</ul>
</div>
</section>
<section>
<h2>Tools</h2>
<h3>Other Plugins</h3>
<ul>
<li>Visual Studio 2012
<ul>
<li>TypeScript for VS2012</li>
<li>Web Essentials (VS2012)</li>
</ul>
</li>
<li>WebMatrix</li>
<li>Sublime Text</li>
<li>Emacs</li>
<li>Vim</li>
<li>WebStorm (coming soon?)</li>
</ul>
</section>
</section>
<section>
<section>
<h2>Other Stuff</h2>
<h3>Source Maps</h3>
<div> <span>Allows you to debug TypeScript in</span><br><span>the browser using </span><span class="underline">original source</span></div>
<div class="break">
<ul>
<li>Available via command-line
<pre>> tsc --sourcemap app.ts</pre>
</li>
<li>Browser support is limited, standard is emerging quickly</li>
</ul>
</div>
</section>
<section>
<h2>The Not So Good Parts</h2>
<ul>
<li>Tools and plugins are still clumsy</li>
<li>Lacks support for generics</li>
<li>Type annotations require more code</li>
<li>3rd party integration is painful
<ul>
<li>DefinitelyTyped is great for common libraries!</li>
<li>Cast to <any> to go "unsafe"</li>
<li>Code generation?</li>
</ul>
</li>
<li>Dynamic bindings, client templates are not strongly typed
<ul>
<li>AngularJS, Knockout</li>
<li>Mustache, Handlebars, Underscore</li>
</ul>
</li>
</ul>
</section>
<section>
<h1>Questions</h1><br>
<div>Thanks for listening!</div><br>
<div class="break">
<h3>Download the slides</h3><a href="https://github.com/jeremyalan/TypeScript-TheGoodParts">https://github.com/jeremyalan/TypeScript-TheGoodParts</a>
</div>
<div class="break">
<h3>Contact me</h3>
<div><span>@jeremyalan</span><br><span>[email protected]</span></div>
</div>
</section>
</section>
</div>
</div>
<script src="lib/js/head.min.js"></script>
<script src="js/reveal.min.js"></script>
<script type="text/javascript">
// Full list of configuration options available here:
// https://github.com/hakimel/reveal.js#configuration
Reveal.initialize({
controls: true,
progress: true,
history: true,
center: true,
theme: Reveal.getQueryHash().theme, // available themes are in /css/theme
transition: Reveal.getQueryHash().transition || 'linear', // default/cube/page/concave/zoom/linear/fade/none
width: 960,
height: 700,
maxScale: 5.0,
rollingLinks: true,
// Optional libraries used to extend on reveal.js
dependencies: [
{ src: 'lib/js/classList.js', condition: function() { return !document.body.classList; } },
{ src: 'plugin/markdown/showdown.js', condition: function() { return !!document.querySelector( '[data-markdown]' ); } },
{ src: 'plugin/markdown/markdown.js', condition: function() { return !!document.querySelector( '[data-markdown]' ); } },
{ src: 'plugin/highlight/highlight.js', async: true, callback: function() { hljs.initHighlightingOnLoad(); } },
{ src: 'plugin/zoom-js/zoom.js', async: true, condition: function() { return !!document.body.classList; } },
{ src: 'plugin/notes/notes.js', async: true, condition: function() { return !!document.body.classList; } }
// { src: 'plugin/search/search.js', async: true, condition: function() { return !!document.body.classList; } }
// { src: 'plugin/remotes/remotes.js', async: true, condition: function() { return !!document.body.classList; } }
]
});
</script>
</body>
</html>