Horje
TypeScript Uppercase<StringType> Template Literal Type

TypeScript Uppercase<StringType> template literal type transforms the characters of StringType to uppercase, ensuring that any string value assigned to it is represented in all uppercase letters.

Syntax:

type Geek= Uppercase<GFG>

Parameters:

  • StringType: It is the input string or string literal type you want to convert to uppercase.
  • Uppercase<StringType>: transforms all characters in StringType to uppercase, returning the resulting uppercase string type.

Example 1: This example showcases how to convert a lowercase string to uppercase using the Uppercase<StringType> Template Literal in TypeScript, allowing the creation of a constant with the string entirely in uppercase characters.

Javascript

type gfg = "horje"
type geek = Uppercase<gfg>
const result: geek = "GEEKSFORGEEKS"
console.log(result)

Output:

GEEKSFORGEEKS

Example 2: In this example, we define a type symbol with possible values “alpha,” “beta,” or “gamma.” It then creates a type geek by converting these values to uppercase. The result variable is assigned “ALPHA” and logs it to the console.

Javascript

type symbols = "alpha" | "beta" | "gama";
type geek = Uppercase<symbols>
const result:geek="ALPHA"
console.log(result)

Output:

ALPHA

Reference: https://www.typescriptlang.org/docs/handbook/2/template-literal-types.html#uppercasestringtype




Reffered: https://www.geeksforgeeks.org


Geeks Premier League

Related
TypeScript Object Type Property Modifiers TypeScript Object Type Property Modifiers
Object Oriented System | Object Oriented Analysis &amp; Design Object Oriented System | Object Oriented Analysis &amp; Design
TypeScript Function TypeScript Function
TypeScript Assignability of Functions TypeScript Assignability of Functions
JavaScript Program to Rearrange Array Alternately JavaScript Program to Rearrange Array Alternately

Type:
Geek
Category:
Coding
Sub Category:
Tutorial
Uploaded by:
Admin
Views:
12