Class functions

All functions within a class adhere to the syntax and rules that we covered in the previous chapter on functions. As a refresher of these rules, all class functions can:

  • Be strongly typed
  • Use the any keyword to relax strong typing
  • Have Optional parameters
  • Have Default parameters
  • Use argument arrays, or the rest parameter syntax
  • Allow function callbacks and specify the function callback signature
  • Allow function overloads

As an example of each of these rules, let's examine a class that has a number of different function signatures, and we will then discuss each one in detail, as follows:

class ComplexType implements IComplexType { id: number; name: string; constructor(idArg: number, nameArg: string); constructor(idArg: string, ...

Get Mastering TypeScript 3 - Third Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.