Hands-On TypeScript for C# and .NET Core Developers

Book description

Discover how TypeScript allows you to build modern client-rich applications, thanks to its object-oriented capabilities and third-party tools like Angular and Web APIs

Key Features

  • Make a seamless transition to using TypeScript 3.1 in your development stack
  • Work with TypeScript 3.1 in your ASP.NET Core projects to build rich applications that are easy to maintain
  • Build, test, and integrate your own TypeScript library in real-world projects

Book Description

Writing clean, object-oriented code in JavaScript gets trickier and complex as the size of the project grows. This is where Typescript comes into the picture; it lets you write pure object-oriented code with ease, giving it the upper hand over JavaScript. This book introduces you to basic TypeScript concepts by gradually modifying standard JavaScript code, which makes learning TypeScript easy for C# ASP.NET developers.

As you progress through the chapters, you'll cover object programming concepts, such as classes, interfaces, and generics, and understand how they are related to, and similar in, both ES6 and C#. You will also learn how to use bundlers like WebPack to package your code and other resources. The book explains all concepts using practical examples of ASP.NET Core projects, and reusable TypeScript libraries. Finally, you'll explore the features that TypeScript inherits from either ES6 or C#, or both of them, such as Symbols, Iterables, Promises, and Decorators.

By the end of the book, you'll be able to apply all TypeScript concepts to understand the Angular framework better, and you'll have become comfortable with the way in which modules, components, and services are defined and used in Angular. You'll also have gained a good understanding of all the features included in the Angular/ASP.NET Core Visual Studio project template.

What you will learn

  • Organize, test, and package large TypeScript code base
  • Add TypeScript to projects using TypeScript declaration files
  • Perform DOM manipulation with TypeScript
  • Develop Angular projects with the Visual Studio Angular project template
  • Define and use inheritance, abstract classes, and methods
  • Leverage TypeScript-type compatibility rules
  • Use WebPack to bundle JavaScript and other resources such as CSS to improve performance
  • Build custom directives and attributes, and learn about animations

Who this book is for

If you're a C# or .NET developer looking for an easy accessible way of learning TypeScript, this book is for you.

Table of contents

  1. Title Page
  2. Copyright and Credits
    1. Hands-On TypeScript for C# and .NET Core Developers
  3. Dedication
  4. Packt Upsell
    1. Why subscribe?
    2. Packt.com
  5. Contributors
    1. About the author
    2. About the reviewers
    3. Packt is searching for authors like you
  6. Preface
    1. Who this book is for
    2. What this book covers
    3. To get the most out of this book
      1. Download the example code files
      2. Download the color images
      3. Code in Action
      4. Conventions used
    4. Get in touch
      1. Reviews
  7. Introduction to TypeScript
    1. Basics and installation
      1. Adding types to JavaScript
      2. Using JavaScript of the future now!
      3. Installing the Visual Studio 2017 TypeScript SDK
      4. Installation of Node.js-based TypeScript compiler
    2. Adding TypeScript to your web projects
      1. Your first TypeScript file
      2. Running and debugging TypeScript code
    3. TypeScript compiler options
      1. Specifying parameters for the TypeScript compiler
      2. TypeScript configuration file
    4. Basic types
      1. TypeScript type system
      2. any and unknown
      3. Strings, numbers, and Booleans
      4. The null and undefined subtypes
      5. Basics of union types
      6. void
      7. never
      8. Enums
    5. Declarations and scoping 
      1. Declarations
      2. Obligatoriness of declarations and noImplicitAny
      3. Variable scoping
      4. Expressions – type assertions, and string interpolation
    6. Summary
    7. Questions
    8. Further reading
  8. Complex Types and Functions
    1. Technical requirements
    2. Arrays and tuples
      1. Array declaration
      2. Tuples
    3. Interfaces and type inference
      1. Interfaces basics
      2. Readonly properties
      3. Optional properties
      4. Excess property check
      5. Defining function properties in interfaces
      6. Indexable types
      7. Interface inheritance
    4. Operations on types
      1. Intersection types
      2. Union types and type guards
      3. Discriminated unions
    5. Destructuring and spreads
      1. Array destructuring
      2. Array spreads
      3. Tuples destructuring
      4. Object destructuring
      5. Object spreads
    6. Functions
      1. Anonymous functions and function types
      2. Optional arguments and destructuring
      3. Function overloads
      4. Arrow functions
    7. Summary
    8. Questions
    9. Further reading
  9. DOM Manipulation
    1. Technical requirements
    2. DOM types
      1. TypeScript predefined declarations
      2. DOM basic types
      3. HTML specific types
    3. Basic DOM operations
      1. DOM manipulation utilities
      2. Removing an item
      3. Adding a new item
    4. Declaration files and JavaScript libraries
      1. Where to find declaration files
      2. How to use TypeScript declaration files
    5. DOM operations with jQuery
    6. Summary
    7. Questions
    8. Further reading
  10. Using Classes and Interfaces
    1. Technical requirements
    2. Classes
      1. Constructors
      2. Members definition and modifiers
      3. Implicit property definition
      4. Accessors
    3. Static members and static parts of a class
      1. What is the type of a class object?
    4. Inheriting from a class and implementing interfaces
      1. Implementing interfaces 
      2. Inheriting from a class
      3. Abstract classes and methods
      4. Modular design with inheritance, interfaces, and abstract classes
    5. Advanced type-compatibility 
    6. Summary
    7. Questions
    8. Further reading
  11. Generics
    1. Technical requirements
    2. Generic functions and interfaces
      1. A generic function for aggregating array elements
    3. Generic classes
    4. Generic constraints
      1. Type constraints
      2. Creating instances of generic variables
    5. The keyof constraints
    6. Summary
    7. Questions
  12. Namespaces and Modules
    1. Technical requirements
    2. Namespaces
      1. DOM manipulation re-engineered with namespaces
    3. Pitfalls of namespaces and ES6 modules
      1. Exporting module symbols
      2. Importing module symbols
      3. Default export and import
      4. Using ES6 modules in browsers
      5. DOM manipulation re-engineered with modules
    4. Loading modules
      1. Compile-time and runtime module-resolution
      2. Non-relative path module-resolution
      3. Dynamic-loading module
    5. Writing declaration files
      1. Ambient modules
      2. Automatic generation of declaration files
    6. Summary
    7. Questions
    8. Further reading
  13. Bundling with WebPack
    1. Technical requirements
    2. Bundling TypeScript and JavaScript
      1. WebPack loaders – bundling TypeScript files
      2. WebPack plugins – recovering the Visual Studio debugger 
      3. The WebPack module's resolution algorithm
    3. Integrating WebPack in ASP.NET Core middleware
      1. Watch mode and Hot Modules Replacement
    4. Optimizing bundles
      1. Library bundling – DllPlugin
      2. Automatic common chunk extraction – SplitChunksPlugin
      3. Dynamic loading
    5. Production and development configurations
    6. Bundling CSS, images, and HTML
      1. Bundling images
      2. Bundling HTML
      3. Bundling CSS
    7. Summary
    8. Questions
    9. Further reading
  14. Building TypeScript Libraries
    1. Technical requirements
    2. Using VS Code
    3. Building your library
      1. Packaging your library as an npm package
    4. Installing a test framework – Jasmine
    5. Testing your library with Jasmine
      1. Writing domlist library tests
      2. Debugging tests
    6. Summary
    7. Questions
    8. Further reading
  15. Decorators and Advanced ES6 Features
    1. Technical requirements
    2. Symbols
      1. Well-known symbols
        1. Symbol.toStringTag
        2. Symbol.toPrimitive
        3. Symbol.search, Symbol.match, and Symbol.replace
        4. Symbol.split
    3. Iterators, iterables, and generators
      1. Iterators and iterables
      2. Generator functions and iterables
      3. Inheriting from Array<T>
      4. ECMAScript 2015 built-in iterables
        1. Map<K, V> and WeakMap<K, V>
        2. Set<T> and WeakSet<T>
    4. Promises and async/await notation
      1. fetch API
      2. async/await notation
    5. Decorators and metadata
      1. Class decorators
      2. Decorator factories
      3. JavaScript built-in metadata – PropertyDescriptor
      4. Method and accessor decorators
      5. Handling metadata with the reflect-metadata polyfill
      6. Parameter decorators
      7. Property decorators
      8. Automatic generation of metadata
    6. Summary
    7. Questions
    8. Further reading
  16. Angular ASP.NET Core Project Template
    1. Technical requirements
    2. Creating an Angular project
    3. Project structure
      1. The main application folder
    4. Angular architecture
      1. How Angular updates the HTML rendered by component templates
    5. Modules, components, and data binding
      1. Template bindings
      2. Style and class bindings
      3. Events and two-way bindings
      4. Angular modules
    6. Configuring and building an Angular application
      1. Building and serving the application
    7. Summary
    8. Questions
  17. Input and Interactions
    1. Technical requirements
    2. Template life cycle events
      1. Angular lifetime events
      2. How to handle Angular life cycle hooks
      3. Using a Bootstrap modal in Angular
      4. Angular update events
    3. Component interaction
      1. Custom two-way bindings
    4. Forms
    5. Pipes
      1. Defining custom pipes
      2. Application localization
    6. Summary
    7. Questions
    8. Further reading
  18. Angular Advanced Features
    1. Technical requirements
    2. Attribute directives
      1. Defining max, min, and step validation attributes
    3. Content projection and structural directives
      1. The inputError directive
      2. Predefined structural directories
    4. Animations
      1. Triggers, states, and state transitions
      2. Parallel and child animations
    5. Summary
    6. Questions
  19. Navigation and Services
    1. Technical requirements
    2. Services and Dependency Injection
      1. Angular injectors' hierarchy
      2. Service providers
      3. Injecting localized error messages
      4. Providers with the same token
    3. Client-server communication
      1. Sending data to the server
      2. Communication progress events
      3. Preventing XSRF attacks
      4. Interceptors
    4. Routing and navigation
      1. Required and optional parameters
      2. Improving routes
      3. Children routes and named router-outlets
      4. Guards
      5. Lazy loaded modules
    5. Testing
    6. Summary
    7. Questions
    8. Further reading
  20. Assessments
    1. Chapter 1
    2. Chapter 2
    3. Chapter 3
    4. Chapter 4
    5. Chapter 5
    6. Chapter 6
    7. Chapter 7
    8. Chapter 8
    9. Chapter 9
    10. Chapter 10
    11. Chapter 11
    12. Chapter 12
    13. Chapter 13
  21. Other Books You May Enjoy
    1. Leave a review - let other readers know what you think

Product information

  • Title: Hands-On TypeScript for C# and .NET Core Developers
  • Author(s): Francesco Abbruzzese
  • Release date: October 2018
  • Publisher(s): Packt Publishing
  • ISBN: 9781789130287