![]() |
TypeScript Literal Inference Type allows you to create type annotations based on actual values, variables, or constants. This enhances type safety and code clarity by specifying that a variable can only hold specific, exact values. It’s a way to express the precise values that a variable can take on, ensuring that your code is more specific and less error-prone. Syntax:const variableName = value as Type;
Parameters:
Example 1: In this example, TypeScript’s type inference is used to create a string literal type, “red,” by defining a constant variable named Javascript
Output: red
Example 2: In this example, we have defined a custom Javascript
Output: Username: GFG1 |
Reffered: https://www.geeksforgeeks.org
Geeks Premier League |
Type: | Geek |
Category: | Coding |
Sub Category: | Tutorial |
Uploaded by: | Admin |
Views: | 13 |