-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathindex.html
More file actions
725 lines (679 loc) · 21.7 KB
/
index.html
File metadata and controls
725 lines (679 loc) · 21.7 KB
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
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
<title>Typescript</title>
<link rel="stylesheet" href="css/reveal.css">
<link rel="stylesheet" href="css/theme/solarized.css">
<link rel="stylesheet" href="css/main.css">
<!-- Theme used for syntax highlighting of code -->
<link rel="stylesheet" href="lib/css/zenburn.css">
<!-- Printing and PDF exports -->
<script>
var link = document.createElement( 'link' );
link.rel = 'stylesheet';
link.type = 'text/css';
link.href = window.location.search.match( /print-pdf/gi ) ? 'css/print/pdf.css' : 'css/print/paper.css';
document.getElementsByTagName( 'head' )[0].appendChild( link );
</script>
</head>
<body>
<div class="reveal">
<div class="slides">
<section>
<h1>Typescript</h1>
<h2>JS for squares</h2>
<p>Chris Mckay</p>
</section>
<section>
<img data-src="/img/javascripthomer.jpg" />
<aside class="notes">
Talking js languages a lot of late. Thought we'd look at some typescript.
</aside>
</section>
<section>
<p>Typescript is...</p>
<ul>
<li class="fragment">Release by Microsoft in 2012, 1.0 in 2014</li>
<li class="fragment">Designed to deal with large-scale application development</li>
<li class="fragment">Strictly typed superset of JS</li>
<li class="fragment">That thing Angular 2 is written in</li>
</ul>
<aside class="notes">
<span>v2.0 late last year</span>
<br/>
<span>Deals with the javascript issues faced in large applications</span>
<br/>
<span>Superset so js is valid ts</span>
<br/>
<span>Flow started in 2014</span>
</aside>
</section>
<section data-background="/img/showmewhatyougot.gif">
</section>
<section>
<table>
<tbody>
<tr>
<td>Algebraic Data Types</td>
<td>Got it</td>
</tr>
<tr>
<td>Higher Kinded Types</td>
<td>Don't got it</td>
</tr>
<tr>
<td>Generics</td>
<td>Got it</td>
</tr>
<tr>
<td>Classes</td>
<td>Got it</td>
</tr>
<tr>
<td>Type classes</td>
<td>Don't got it</td>
</tr>
<tr>
<td>Pattern Matching</td>
<td>Don't got it</td>
</tr>
<tr>
<td>Currying</td>
<td>Don't got it</td>
</tr>
<tr>
<td>First class functions</td>
<td>Got it</td>
</tr>
<tr>
<td>Type inference</td>
<td>Got it</td>
</tr>
</tbody>
</table>
</section>
<section data-background="/img/disqualified.gif">
<aside class="notes">
<span>we're not getting all the cool functional stuff</span>
</aside>
</section>
<section>
Lets look at the language
</section>
<section>
<pre><code class="typescript" data-trim>
var a = 'a';
let b = 'b';
const c = 'c';
</code></pre>
<aside class="notes">
3 variable types. Var is a leaky variable. Let is lexically sealed. Const is lexically sealed
and assignable once, not really immutable though.
</aside>
</section>
<section>
<pre><code class="typescript" data-trim>
const num: number = 3;
const bool: boolean = true;
const str: string = "a string";
</code></pre>
<aside class="notes">
Basic primitives.
<br/>
One type of number, no refinement for floats etc
<br/>
2 strings, you want the lower case one
</aside>
</section>
<section>
<pre><code class="typescript" data-trim>
const nothing: undefined = undefined;
const nada: null = null;
</code></pre>
<aside class="notes">
undef = uninitialised
null = unavailable
they're both basically the same except when they're not.
Just don't use null
</aside>
</section>
<section>
<pre><code class="typescript" data-trim>
const artistFormerlyKnownAs: symbol = Symbol('Prince');
</code></pre>
<aside class="notes">
Symbol, it makes completely unique values. es6, you probably won't need it, it's metaprogramming magic
</aside>
</section>
<section>
<pre><code class="typescript" data-trim>
const yolo: any = 42;
const slightlyLessYolo: object = new Date();
</code></pre>
<aside class="notes">
any is anything
<br/>
Things used to default to any, not commonly seen since 2.0, now recommended to be turned off
<br/>
object is anything not a primitive
</aside>
</section>
<section>
<pre><code class="typescript" data-trim>
const voldemort: never = `boom`;
</code></pre>
<aside class="notes">
never is the bottom type. No equivilence. New with 2.0. Implemented to support control flow analysis.
</aside>
</section>
<section>
<pre><code class="typescript" data-trim>
const youGetNothing: void = undefined;
</code></pre>
<aside class="notes">
Void = return of nothing from a function. In assignment it can only receive undef or null.
</aside>
</section>
<section>
<pre><code class="typescript" data-trim>
function logHello (name: string): void {
console.log('Hello ' + name);
}
function hello (name: string): string {
return 'Hello ' + name;
}
const hello = (name: string): string => {
return 'Hello ' + name;
}
// Infers string => string
const hello = (name: string) => 'Hello ' + name;
</code></pre>
<aside class="notes">
Functions. You've got arrow functions, lambdas. Inference is pretty good but its one directional, forward or down depending on your perspective.
</aside>
</section>
<section>
<pre><code class="typescript" data-trim>
const stringArray: Array<string> = [ 'a', 'b', 'c' ];
const numberArray: number[] = [ 1, 2, 3 ];
</code></pre>
<aside class="notes">
arrays. Community leans towards the square brackets trailing. Matches c# and doesn't confuse jsx
</aside>
</section>
<section>
<pre><code class="typescript" data-trim>
interface Point {
x: number;
y: number;
label?: string;
}
interface Point3D extends Point {
z: number;
}
</code></pre>
<aside class="notes">
Interfaces are data types. Inheritence and multiple inheritence.
? is optional key.
</aside>
</section>
<section>
<pre><code class="typescript" data-trim>
interface BirthdayCard {
message: string;
}
interface TerminationLetter {
message: string;
}
const badNews: TerminationLetter = {
message: "you're fired"
};
const happyBirthday: BirthdayCard = badNews;
</code></pre>
<aside class="notes">
Structural typing. The type names mean nothing. So long as the structure of the types are the same its equivelent. So long as the structure contains at least what is required then it can fulfil it.
</aside>
</section>
<section>
<pre><code class="typescript" data-trim>
class Queue {
private data: string[] = [];
constructor(seed: string[] = []) {
this.data = seed;
}
push = (item: string) => this.data.push(item);
pop = () => this.data.shift();
}
const queue = new Queue(['seed', 'values']);
</code></pre>
<aside class="notes">
Classes are es6 classes. Compile down fine. Types here are realish and can be referred to at run time. Can extend interfaces.
</aside>
</section>
<section>
<pre><code class="typescript" data-trim>
class Queue<T> {
private data: T[];
constructor(seed: T[] = []) {
this.data = seed;
}
push = (item: T) => this.data.push(item);
pop = () => this.data.shift();
}
const queueNumbers = new Queue<number>([1, 2]);
// Inferred as Queue<number>
const numbersQueue = new Queue([1,2]);
</code></pre>
<aside class="notes">
Generics. Classes, interfaces and functions can be paramaterized across types allowing for parametric code.
<br/>
Can explicitly define the type params
<br/>
Can be inferred, but only forwards/down
</aside>
</section>
<section>
<pre><code class="typescript" data-trim>
interface Payload {
id: string;
}
interface MessagePayload extends Payload {
message: string;
}
class Action<P extends Payload> {
private payload: P;
constructor(payload: P) {
this.payload= payload;
}
payloadId = () => this.payload.id;
}
</code></pre>
<aside class="notes">
Can constrain the generic parameters. Can also constrain in terms of other parameters.
</aside>
</section>
<section>
<pre><code class="typescript" data-trim>
interface Cat {
smiling: boolean,
teeth: number
}
interface Bus {
speed: number,
capacity: number
}
type CatOrBus = Cat | Bus;
type CatBus = Cat & Bus;
</code></pre>
<aside class="notes">
ADT's, | is a type union. The variable assigned to it must fulfil at least 1 of its member types requirements. & is an intersection type. values must fulfil all of its member types requirements
</aside>
</section>
<section>
<img height="200" alt="" src="/img/kona.jpg"/>
<pre><code class="typescript" data-trim>
type CutePuppy = 'Kona';
const cutePuppy: CutePuppy = 'Kona';
</code></pre>
<aside class="notes">
Last type, type literals. Type can be a value. Restricts assignment to just that value.
</aside>
</section>
<section>
<img height="200" alt="" src="/img/kona.jpg"/>
<img height="200" alt="" src="/img/monty.jpg"/>
<pre><code class="typescript" data-trim>
type CutePuppy = 'Kona' | 'Monty';
const cutePuppies: CutePuppy[] = ['Kona', 'Monty'];
</code></pre>
<aside class="notes">
Lets you build things like enums
</aside>
</section>
<section>
<pre><code class="typescript" data-trim>
interface Blossom {
colour: 'Pink';
freeze(): void;
}
interface Bubbles {
colour: 'Blue';
scream(): void;
}
type PowerpuffGirl = Blossom | Bubbles;
</code></pre>
<aside class="notes">
Also use them for type information. You can have a member variable thatas reliably a certain value.
</aside>
</section>
<section>
<pre><code class="typescript" data-trim>
const doSuperPower = (girl: PowerpuffGirl) => {
// colour is available on both
if (girl.colour === 'Pink') {
// The girl is Blossom in here
girl.freeze();
} else {
// The girl is Bubbles here
p.scream();
}
}
</code></pre>
<aside class="notes">
control flow analysis figures out what the value possibly could be at each point
</aside>
</section>
<section>
<pre><code class="typescript" data-trim>
interface Buttercup {
colour: 'Green';
fight(): void;
}
type PowerpuffGirl = Blossom | Bubbles | Buttercup;
</code></pre>
<aside class="notes">
There's 3 powerpuff girls though
</aside>
</section>
<section>
<pre><code class="typescript" data-trim>
const doSuperPower = (girl: PowerpuffGirl) => {
// colour is available on both
if (girl.colour === 'Pink') {
// The girl is Blossom in here
girl.freeze();
} else {
// Error here The girl could be Bubbles or Buttercup
p.scream();
}
}
</code></pre>
<aside class="notes">
The controll flow analysis figures out we haven't been discriminatory enough
</aside>
</section>
<section>
<pre><code class="typescript" data-trim>
const whatsHerName = (girl: PowerpuffGirl): string {
switch (girl.colour) {
case 'Pink': return 'Blossom';
case 'Blue': return 'Bubbles';
case 'Green': return 'Buttercup';
}
}
</code></pre>
<aside class="notes">
Great for switches
Not great, doesn't work properly for if-else. Side effect of how control flow analysis done, they're trying to fix it.
</aside>
</section>
<section>
<pre><code class="typescript" data-trim>
// Module.ts
export const myExport = "Export Me";
// Index.ts
import { myExport } from './Module';
</code></pre>
<aside class="notes">
Module system is exactly like in es6. All the same behaviours and You export things and import them.
Nothing interesting to go into except for how typing gets involved.
</aside>
</section>
<section>
<pre><code class="typescript" data-trim>
declare function moment(...): moment.Moment;
declare namespace moment {
type RelativeTimeKey = 's' | ... ;
interface Moment extends Object{
format(format?: string): string;
...
}
}
export = moment;
</code></pre>
<aside class="notes">
ambient declarations. Namespaces are modules of interface descriptions and functional descriptions. Can export top level stuff too.
Can declare globally available variables, attach things to window, etc.
</aside>
</section>
<section>
<img alt="" src="/img/definitelytypedrepo.png" />
<aside class="notes">
definitely typed module count, dates?
</aside>
</section>
<section>
<img alt="" src="/img/npmjstypes.png"/>
<aside class="notes">
As of typescript 2.0. Types managed by npm rather than 'typings' tool. Exported from definitelytyped
</aside>
</section>
<section>
<ul>
<li>/node_modules/moment/index.d.ts</li>
<li>/node_modules/@types/moment/index.d.ts</li>
<li>/types/moment/index.d.ts</li>
</ul>
<aside class="notes">
Looks first for ambient declaration in your source, then in shipped npm package, then in @types packages
</aside>
</section>
<section>
<img alt="" src="/img/tsc.png"/>
<aside class="notes">
Theres a compiler, Lots of options, not that interesting, but the JS it outputs is
</aside>
</section>
<section>
<img alt="" src="/img/tsjsemit.png"/>
<aside class="notes">
outputs es6 or es5 or es3.
<br/>
Most language features compile to es3.
<br/>
ts is close to JS to emitted code is close to what you wrote
<br/>
No chunky prelude etc to compile in, just the same esX polyfills you'd be using anyway.
</aside>
</section>
<section>
<img width=200 alt="" src="/img/tslint.jpg"/>
<br/>
<img alt="" src="/img/tslinteg.jpg"/>
<aside class="notes">
tslint is powerful.
<br/>
Regular linting very good
<br/>
Semantic linting uses type & control flow analysis
<br/>
e.g. JqueryDeferred must have reject or resolve called on it in all branches
</aside>
</section>
<section>
But Why?
<aside class="notes">
Nothing presented so far is that different from flow. Significantly worse than purescript or ghcjs or elm.
So why use this one
</aside>
</section>
<section>
<blockquote cite="Tony Morris">
<p>
“I can't write correct javascript and I haven't met anyone else who can either.”
</p>
<div style="text-align:right">
- Tony Morris
</div>
</blockquote>
<aside class="notes">
I don't think I have to convince anyone here that coding in JS isn't a great idea
</aside>
</section>
<section>
<img src="/img/javascripteverywhere.jpeg" alt="" />
<aside class="notes">
But its still everywhere, browsers, servers
</aside>
</section>
<section>
<img alt="" src="/img/dynamic-languages-godfather.jpg"/>
<aside class="notes">
Most problems are runtime errors
</aside>
</section>
<section>
<img alt="" src="/img/type-error-jesus.jpg"/>
<aside class="notes">
We can fix those types of errors
</aside>
</section>
<section>
<img src="/img/purescriptwindow.jpg" alt="" />
<aside class="notes">
It's a hard sell to reskill existing teams and beligerant managers
</aside>
</section>
<section>
<img src="/img/canttelltypescript.jpg" alt="" />
<aside class="notes">
Typescript is close enough that you don't need to reskill
<br/>
existing devs can read/write it
</aside>
</section>
<section>
<img alt="" src="/img/vscode.png"/>
<aside class="notes">
Awesome tools. vs code is Awesome. Fast, clean. Intellisense & documentation mapping. Great plugin support. Constant updates.
</aside>
</section>
<section>
<table>
<tr>
<td>vim</td>
<td>Tsuquyomi</td>
</tr>
<tr>
<td>emacs</td>
<td>Tide</td>
</tr>
</table>
<aside class="notes">
Both do intellisense omnicompletion. Tide has been excellent for me.
</aside>
</section>
<section>
<ul>
<li>Angular 2</li>
<li>RxJS</li>
<li>VS Code</li>
<li>ionic</li>
<li>Sodium</li>
<li>CycleJS</li>
</ul>
<aside class="notes">
Community adoption. Some big projects are driving it
</aside>
</section>
<section>
<h3>Stack Overflow</h3>
<table>
<tr>
<td>Javascript</td>
<td>1,444,140</td>
</tr>
<tr>
<td>Typescript</td>
<td>34,355</td>
</tr>
<tr>
<td>Elm</td>
<td>997</td>
</tr>
<tr>
<td>Flow</td>
<td>474</td>
</tr>
<tr>
<td>Purescript</td>
<td>252</td>
</tr>
<tr>
<td>GHCJs</td>
<td>74</td>
</tr>
</table>
<aside class="notes">
Enough people using it to catch the problems before you do and fix it
<br/>
Great getting on irc and asking bodil about purescript or Luite about ghcjs
</aside>
</section>
<section>
3385 packages in Definitely Typed
<aside class="notes">
No point gradual typing, and you don't want to do the work typing the world. You want it typed for you.
</aside>
</section>
<section>
<ul>
<li>Video courses</li>
<li>Books by every major publisher</li>
<li>Community guides</li>
</ul>
<aside class="notes">
Educational resources being developed
</aside>
</section>
<section>
<pre><code class="typescript" data-trim>
const some = Option(33) // some === Some(33)
const none = Option(null) // none === None
const some = Option.all(
Option(10),
Option(5)
)
// some === Some([10, 5])
const none = Option.all(
Option(10),
None,
Option(5),
)
// none === None
</code></pre>
</section>
<section>
It's just enough
<aside class="notes">
More has been invested in typescript than any of its competitors. It aims a lot lower, but you know where you need to go if you want to stretch higher
</aside>
</section>
<section>
Questions?
</section>
</div>
</div>
<script src="lib/js/head.min.js"></script>
<script src="js/reveal.js"></script>
<script>
// More info about config & dependencies:
// - https://github.com/hakimel/reveal.js#configuration
// - https://github.com/hakimel/reveal.js#dependencies
Reveal.initialize({
history: true,
controls: true,
slideNumber: true,
center: true,
dependencies: [
{ src: 'plugin/markdown/marked.js' },
{ src: 'plugin/markdown/markdown.js' },
{ src: 'plugin/notes/notes.js', async: true },
{ src: 'plugin/highlight/highlight.js', async: true, callback: function() { hljs.initHighlightingOnLoad(); } }
]
});
</script>
</body>
</html>