| Start |
|---|
| Optional and Default Parameters Optional Parameters In TypeScript, every parameter is assumed to be required by the function. You can add a ? at the end of a parameter name to set it as optional. For example, the Optional parameters must come after all non-optional parameters: Default Parameters If the user passes For example, "Smith" is the default value for the |
| Types of Functions Named functions Anonymous functions Lambda / arrow functions |
| Function as a parameter Suppose we want to receive a function as a parameter, we can do it like this: If we want to receive a constructor as a parameter: Or to make it easier to read we can define an interface describing the constructor: Or with parameters: Even with generics: If we want to receive a simple function and not a constructor it's almost the same: Or to make it easier to read we can define an interface describing the function: Or with parameters: Even with generics: |
| Functions with Union Types A TypeScript function can take in parameters of multiple, predefined types using union types. Typescript treats these parameters as a single type that is a union of the other types, so your function must be able to handle parameters of any type that is in the union. RemarksTypescript documentation link for Functions (opens new window) |
Read Article
https://develop.horje.com/learn/1434/reference