Jan 2, 2023

TypeScript: Any, Unknown and Never

As part of this blog, we will explore special type annotations. We will be looking at some unique TypeScript annotations in addition to how type annotations work.

Author

Ponikar Darshan JanardanPonikar Darshan JanardanSoftware Engineer - I
TypeScript: Any, Unknown and Never

1. Any

anyis like an escape hatch; it can be used when you are not sure about a type. When you use any type annotation, you are just saying to TypeScript:

"Hey TypeScript, I don't have any idea about this type. So don't bother to check this type."

You should avoid any annotation for as long as possible. Using any is similar to using javascript without type safety.

Following is an example of any :

let a:any = "Hello world"

// We lost type safety!
a = 123;

const myFunctions = (args: any) => {
 // ..
// ...
}

2. Unknown

When you use unknown type annotation, you are just saying to TypeScript:

"Hey, TypeScript, I'm not sure about this type, but please remind me to check it during runtime."

unknown is like a safeguard. By checking types at runtime, we can ensure that we are not writing any buggy code.

const myFun = (args: unknown) => {

   // this will give you an error since the type is unknown.
   const length = args.length;

  // we are checking if args is having string type or not.
    if(typeof args === "string") {
           return args.slice(0,2);
    }
}

3. Never

never is useful when you are working with type manipulation. never simply means that the type doesn't exist anymore.

It is used to filter types and perform error handling. Let's assume we are writing a function, and we are sure that this function will throw an error. Since this function is not returning anything and our program will likely be stopped, we can assign never as the return type.

const crashCode = () :never => {
     throw new Error("Boom...");
}

This example might not make sense to you now, but there are plenty of situations in which never can be really useful.

You are now aware of the specific type annotations. This will aid in understanding complex TypeScript ideas such as utility types, type of types, condition types, and so on. Keep an eye out for future blogs.

Thanks for reading this blog, until next time!

Subscribe to Our Newsletter

RELATED ARTICLES

More from the engineering frontline.

Dive deep into our research and insights on design, development, and the impact of various trends to businesses.
Why Legacy Systems Block Real-Time AI Decision-Making
Business

Aug 4, 2026

Why Legacy Systems Block Real-Time AI Decision-Making
Learn how legacy systems limit real-time AI decision-making and what businesses can do to build an AI-ready infrastructure.
What Makes an AI Product Enterprise-Ready? A Business Leader’s Perspective
Business

Aug 4, 2026

What Makes an AI Product Enterprise-Ready? A Business Leader’s Perspective
Most AI pilots never make it to production. Here are the five questions business leaders should ask before approving, buying, or scaling an AI product.
Building AI-Powered Banking CRM Platforms Without Replacing Core Banking Systems
Business

Jul 31, 2026

Building AI-Powered Banking CRM Platforms Without Replacing Core Banking Systems
Banks can modernize CRM with AI without replacing their core banking systems. This guide covers the architecture, use cases, governance, and roadmap to do it.
AI in Fintech: Everyone's Talking, Few are Shipping
Business

Jul 30, 2026

AI in Fintech: Everyone's Talking, Few are Shipping
This blog covers the key engineering, governance, and compliance principles required to build production-ready AI systems for financial services.
ERP and MES Integration for U.S. Pharma Manufacturers: A Roadmap to Achieve Zero-Error Production and End-to-End Traceability
Business

Jul 27, 2026

ERP and MES Integration for U.S. Pharma Manufacturers: A Roadmap to Achieve Zero-Error Production and End-to-End Traceability
A strategic roadmap for U.S. pharma leaders integrating ERP and MES to reduce production errors, accelerate batch release, strengthen compliance readiness, and enable end-to-end traceability across manufacturing sites.
How to Build Medical Device Software with AI: Compliance, Architecture, and Development Process
Business

Jul 24, 2026

How to Build Medical Device Software with AI: Compliance, Architecture, and Development Process
A guide for engineering leaders on building compliant, production-ready AI medical device software, from architecture to FDA clearance.

The Right Conversation Can Save You Six Months.

Whether you’re navigating AI adoption, modernizing legacy systems, or scaling a product - we start by listening. No pitch deck. No template. A real conversation.