TypeScript is a typed language. However, it is not mandatory to specify the type of a variable. TypeScript infers types of variables when there is no explicit information available in the form of type annotations.
Types are inferred by TypeScript compiler when:
1. Variables are initialized
2. Default values are set for parameters
3. Function return types are determined
Example
Demo
Demo Inference
No comments:
Post a Comment