Open In App

TypeScript Uppercase<StringType> Template Literal Type

Last Updated : 26 Feb, 2024
Improve
Improve
Like Article
Like
Save
Share
Report

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 = "geeksforgeeks"
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


Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads