TypeScript Assertions Type Last Updated : 11 Mar, 2025 Comments Improve Suggest changes Like Article Like Report TypeScript Assertions Type, also known as Type Assertion, is a feature that lets developers manually override the inferred or expected type of a value, providing more control over type checking in situations where TypeScript's automatic type inference may not be sufficient.Syntaxlet variableName: AssertedType = value as AssertedType; ParametersvariableName: This is the name of the variable you want to assign the asserted value to.AssertedType: This is the type you are telling TypeScript to treat the value as. It should be a valid TypeScript type.value: This is the value that you want to assert the type for. It can be a variable, an expression, or a function return value.Example 1: In this example, the value is initially declared as any(value as string), which is a type assertion, telling TypeScript to treat the value as a string. This allows us to access the length property on the assumed string type. We log both the original value and the length to the console. JavaScript let value: any = "Hello, Geek!"; let len: number = (value as string).length; console.log(`Value: ${value}`); console.log(`Length: ${len}`); OutputValue: Hello, Geek!Length: 12Example 2: In this example, defines an object 'person' with mixed types, then uses a type assertion to specify a more specific type for 'personDetails' and displays its 'name' and 'website' properties. JavaScript // Define an object with mixed types const person: any = { name: "GeeksforGeeks", website: "www.geeksforgeeks.org", }; // Type assertion to specify // a more specific type const personDetails = person as { name: string; website: string; }; // Access and display the person's details console.log(`Name: ${personDetails.name}`); console.log(`Website: ${personDetails.website}`); OutputName: GeeksforGeekswebsite: www.geeksforgeeks.org Comment More infoAdvertise with us Next Article TypeScript Assertions Type A akshitsaxenaa09 Follow Improve Article Tags : JavaScript Web Technologies Geeks Premier League TypeScript Geeks Premier League 2023 +1 More Similar Reads Explain Type assertions in TypeScript In TypeScript, type assertions allow developers to override the compiler's inferred type, informing it of the specific type of a value. Type assertions are purely compile-time constructs and do not alter the runtime behavior of the code. They are particularly useful when interfacing with APIs or thi 3 min read TypeScript Assertion functions TypeScript Assertion functions are nothing but the functions that allow us to mainly create the custom type guards that assert the type of a value on our specific criteria. The most suitable use of Assertion Functions is when we are working with the more complex data structures. Syntax:function asse 3 min read TypeScript Conditional Types In TypeScript, conditional types enable developers to create types that depend on a condition, allowing for more dynamic and flexible type definitions.They follow the syntax T extends U ? X : Y, meaning if type T is assignable to type U, the type resolves to X; otherwise, it resolves to Y.Conditiona 4 min read TypeScript Custom Type Guards TypeScript boasts a powerful type system, which helps the developers catch errors at compile time and write more resilient code. Sometimes you would need to work with complex types or dynamically typed data where the type information might not be readily available. In situations like these, TypeScri 7 min read TypeScript Truthiness Narrowing Type In this article, we are going to learn about Truthiness narrowing Type in Typescript. TypeScript is a popular programming language used for building scalable and robust applications. In TypeScript, truthiness narrowing is a concept that allows you to narrow down the type of a variable based on its t 3 min read Like