[TYPESCRIPT][TypeScript Succinctly].pdf

(2156 KB) Pobierz
1
By
Steve Fenton
Foreword by Daniel Jebaraj
2
Copyright © 2013 by Syncfusion Inc.
2501 Aerial Center Parkway
Suite 200
Morrisville, NC 27560
USA
All rights reserved.
I
mportant licensing information. Please read.
This book is available for free download from
www.syncfusion.com
on completion of a
registration form.
If you obtained this book from any other source, please register and download a free copy from
www.syncfusion.com.
This book is licensed for reading only if obtained from
www.syncfusion.com.
This book is licensed strictly for personal, educational use.
Redistribution in any form is prohibited.
The authors and copyright holders provide absolutely no warranty for any information provided.
The authors and copyright holders shall not be liable for any claim, damages, or any other
liability arising from, out of, or in connection with the information in this book.
Please do not use this book if the listed terms are unacceptable.
Use shall constitute acceptance of the terms listed.
SYNCFUSION, SUCCINCTLY, DELIVER INNOVATION WITH EASE, ESSENTIAL, and .NET
ESSENTIALS are the registered trademarks of Syncfusion, Inc.
E
3
dited by
This publication was edited by Praveen Ramesh, director of development, Syncfusion, Inc.
Table of Contents
The Story behind the
Succinctly
Series of Books .................................................................................. 8
About the Author ....................................................................................................................................... 10
Introduction ............................................................................................................................................... 11
Is TypeScript the Answer? ..................................................................................................................... 11
Who is This Book For?........................................................................................................................... 11
What is Missing? .................................................................................................................................... 12
Code Samples ....................................................................................................................................... 12
Notes ...................................................................................................................................................... 12
Chapter 1 Concepts in TypeScript ......................................................................................................... 13
Code organization .................................................................................................................................. 13
TypeScript Glossary............................................................................................................................... 14
Program ............................................................................................................................................... 14
Module ................................................................................................................................................. 14
Interface ............................................................................................................................................... 14
Class .................................................................................................................................................... 14
Function ............................................................................................................................................... 14
Variable ................................................................................................................................................ 15
Enumeration......................................................................................................................................... 15
Scope ................................................................................................................................................... 15
Compilation ............................................................................................................................................ 15
ECMAScript 3 ...................................................................................................................................... 15
ECMAScript 5 ...................................................................................................................................... 16
ECMAScript 6 ...................................................................................................................................... 16
TypeScript Life Cycle ........................................................................................................................... 16
4
Chapter 2 Visual Studio ........................................................................................................................... 18
Visual Studio Extension ......................................................................................................................... 18
Pre-Build Event ...................................................................................................................................... 19
Trying it Out ........................................................................................................................................... 20
Chapter 3 Type Safety ............................................................................................................................. 21
Static, Dynamic, and Optional Types ..................................................................................................... 21
Inferred Types ........................................................................................................................................ 21
Built-in Types ......................................................................................................................................... 25
Custom Types ........................................................................................................................................ 27
Advanced Type Declarations ................................................................................................................. 27
Type Inference Mechanism.................................................................................................................... 29
Variables and Parameters ................................................................................................................... 29
Functions ............................................................................................................................................. 30
Contextual Typing ................................................................................................................................ 30
Widened Types .................................................................................................................................... 31
When to Use Types ............................................................................................................................... 31
Chapter 4 Creating New Modules ............................................................................................................ 32
Modules.................................................................................................................................................. 32
Declaring a Module .............................................................................................................................. 32
Adding a Class to a Module ................................................................................................................. 33
Interfaces, Classes, and Functions ........................................................................................................ 35
Private Functions ................................................................................................................................. 35
Static Functions ................................................................................................................................... 37
Default Parameters .............................................................................................................................. 38
Optional Parameters ............................................................................................................................ 39
Rest Parameters .................................................................................................................................. 40
Function Overloads .............................................................................................................................. 40
5
Zgłoś jeśli naruszono regulamin