What you can do is check whether you props is defined initially or not by checking if nextProps.blog.content is undefined or not since your body is nested inside it like

componentWillReceiveProps(nextProps) {

    if(nextProps.blog.content !== undefined && nextProps.blog.title !== undefined) {
       console.log("new title is", nextProps.blog.title);
       console.log("new body content is", nextProps.blog.content["body"]);
       this.setState({
           title: nextProps.blog.title,
           body: nextProps.blog.content["body"]
       })
    }
}

You need not use type to check for undefined, just the strict operator !== which compares the value by their type as well as value

In order to check for undefined, you can also use the typeof operator like

typeof nextProps.blog.content != "undefined"
Answer from Shubham Khatri on Stack Overflow
🌐
Akos Komuves
akoskm.com › how-to-solve-variable-is-possibly-undefined-in-typescript-even-when-its-defined
How to solve ”variable is possibly undefined” in TypeScript - even when it’s defined | Akos Komuves
The solution is to either explicitly check for the value before usage or pass the value as a required argument to functions, ensuring type safety and preventing runtime errors. You just learned how you could both improve the readability of your ...
🌐
Tim Mousk
timmousk.com › blog › typescript-check-for-undefined
How To Check For Undefined In TypeScript? – Tim Mouskhelichvili
March 8, 2023 - As you can see, checking for undefined in TypeScript is simple. You just need to do a condition check, and voila. Here are other TypeScript tutorials for you to enjoy: ... Hello! I am Tim Mouskhelichvili, a Freelance Developer & Consultant from Montreal, Canada. I specialize in React, Node.js ...
🌐
Webtips
webtips.dev › solutions › check-undefined-in-typescript
How to Correctly Check Undefined in TypeScript - Webtips
September 21, 2022 - To check for undefined values in TypeScript, you need to use the strict equal operator against the undefined keyword.
🌐
CodingDeft
codingdeft.com › posts › how-to-solve-typescript-possibly-undefined-value
Object is possibly 'undefined' error in TypeScript [Solved] | CodingDeft.com
Nullish coalescing is similar to logical OR operator except that it evaluates to the right side operand only if the left side operand is null or undefined, whereas logical OR (||) operator does it for other falsy values like an empty string, 0, false, etc. You can use nullish coalescing operator as shown below: ... These are the few ways in which you can fix the error. You can use any one of them based on your use case. If you have liked article, do follow me on twitter to get more real time updates! How to fix React Hook warnings for async functions in useEffect
🌐
Atomic Spin
spin.atomicobject.com › optional-undefined-typescript
How to Deal with “Optional” and “Undefined” in TypeScript
November 25, 2024 - TypeScript understands a number of these kinds of checks and can use them to narrow the picture of what types can possibly make it through to a specific bit of code. We can use a typeof check against the bar property to see if it is undefined.
Find elsewhere
🌐
W3Schools
w3schools.com › typescript › typescript_null.php
TypeScript Null & Undefined
Nullish coalescing is another JavaScript feature that also works well with TypeScript's null handling. It allows writing expressions that have a fallback specifically when dealing with null or undefined.
🌐
Bobby Hadz
bobbyhadz.com › blog › react-null-or-undefined-check
Check if a Variable is Null or Undefined in React | bobbyhadz
To check if a variable is null or undefined in React, use the || (or) operator to check if either of the two conditions is met.
🌐
2ality
2ality.com › 2013 › 04 › check-undefined
Checking for undefined: === versus typeof versus falsiness
Recommendation: check for undefined either via === undefined or via falsiness. It is normally more important for code to be easy to understand than to be completely safe.
🌐
Reddit
reddit.com › r/typescript › typescript not acknowledging 'not undefined' assertion
r/typescript on Reddit: Typescript not acknowledging 'not undefined' assertion
November 29, 2023 -

Update: For simplicity, I replicated the original error with simpler code.

Update 2: I got around this by using a type guard for T. Thank u/ritajalilip for the suggestion. I still think Typescript should handle this better though.

As you can see on the screenshot, inside the if statement I'm asserting that x is not undefined. However Typescript is failing to acknowledge and still thinks that x can be undefined.

Any idea of what's going on?

🌐
Upmostly
upmostly.com › home › typescript › how to detect null and undefined
How to Detect Null and Undefined in Your TypeScript Code - Upmostly
March 28, 2023 - Another way to check for null or undefined is to use the nullish coalescing operator (??), which was introduced in TypeScript 3.7.
🌐
Coding Beauty
codingbeautydev.com › home › posts › how to check if a variable is null or undefined in react
How to Check if a Variable is Null or Undefined in React
October 4, 2023 - Instead of checking explicitly for null or undefined, you might be better off checking if the variable is falsy. JavaScriptCopied! import { useState } from 'react'; export default function App() { const [variable] = useState(undefined); const [message, setMessage] = useState(undefined); const falsyCheck = () => { // Check if falsy if (!variable) { setMessage('✅ Variable is falsy'); } else { setMessage('❌ Variable is NOT falsy'); } }; return ( <div> <button onClick={() => falsyCheck()}>Check variable</button> <h2>{message}</h2> </div> ); }
🌐
TypeScript
typescriptlang.org › docs › handbook › release-notes › typescript-2-0.html
TypeScript: Documentation - TypeScript 2.0
The type checker previously considered null and undefined assignable to anything. Effectively, null and undefined were valid values of every type and it wasn’t possible to specifically exclude them (and therefore not possible to detect erroneous use of them). strictNullChecks switches to a new strict null checking mode.
🌐
Reddit
reddit.com › r/typescript › how check for undefined in conditional type
r/typescript on Reddit: How check for undefined in conditional type
November 14, 2023 -

This code do not work at all, but not sure why.

type IsUndefined<T> = T extends undefined ? 1 : 0;

For example:

type IsTypeUndefined = IsUndefined<number | undefined>;
// This returns: 1 | 0

Is there a way for check if a type is undefined in a conditional?

🌐
DEV Community
dev.to › kais_blog › how-to-check-for-undefined-in-javascript-typescript-3men
How to Check For Undefined in JavaScript / TypeScript - DEV Community
January 2, 2021 - So, I suggest that you always use the typeof operator if you are checking for undefined. Let's move your learning forward together! Follow me on Twitter for your daily dose of developer tips.