#30301Medium

IsOdd

return true is a number is odd Master advanced TypeScript type manipulation in this medium-level challenge on TypeScriptPro.

In this medium-level challenge, you'll implement an IsOdd<T> type that determines whether a given number type is an odd integer, returning true for odd integers and false otherwise.

Challenge Instructions: IsOdd

Medium

return true is a number is odd

Change the following code to make the test cases pass (no type check errors).

Loading...

Detailed Explanation

type IsOdd<T extends number> =
  number extends T
    ? false
    : `${T}` extends `${string}${'1' | '3' | '5' | '7' | '9'}`
      ? true
      : false;

How it works:

A more robust solution that also rejects non-integers:

type IsOdd<T extends number> =
  number extends T
    ? false
    : `${T}` extends `${bigint}`
      ? `${T}` extends `${string}${'1' | '3' | '5' | '7' | '9'}`
        ? true
        : false
      : false;

How this improved version works:

This challenge helps you understand template literal types for numeric string analysis and how to apply these patterns in real-world scenarios.

This challenge is originally from here.

Share this challenge

Join early, learn faster.

Be the first to access the course, unlock exclusive launch bonuses, and get special early-bird pricing before anyone else.

No spam, unsubscribe at any time. We respect your privacy.

Limited Availability

Only 27 Spots left

Early Access

Get 1 month early access

>75% Off

Pre-Launch discount