Saturday, November 15, 2025
Latest:
  • What are the main differences between ApplicationContext and BeanFactory?
  • German B1 Word list
  • How does Lazy annotation work in Spring?
  • How Spring framework resolves circular dependencies?
  • German Pronouns with Nominative, Accusative, and Dative cases
Upokary

Upokary

Quality information

  • Health
  • Life
  • Fashion
  • Food
  • Code
  • English
  • বাংলা
Technology 

Type ‘null’ is not assignable to type ‘T’

Published: December 1, 2021 JavaScript, TypeScript

We got into this issue when we tried to return null from a generic function. See the code segment below:

function bar(x: T): T {
  if(x === null){
     return null; 
  }   
}

Solution:

To solve this issue, we can amend the code like below:

function bar(x: T): T | null{
  if(x === null){
     return null; 
  }   
}

OR

function bar(x: T): T {
  if(x === null){
     return null as any; 
  }   
}

You May Also Like

Difference Between Element Sum and Digit Sum of an Array

January 21, 2023 beroza

How to create a dialog or popup using CSS?

June 9, 2022 beroza

How to redirect to another route onclick ReactJS?

October 23, 2019 beroza

How to conditionally apply class attributes in ReactJS?

September 13, 2019 beroza

How to empty a file in linux?

May 17, 2019 beroza

Largest 3-Same-Digit Number in String

December 30, 2022 beroza

rest_cannot_create Sorry, you are not allowed to create posts as this user in WordPress REST API

July 2, 2019 beroza

How to find frequency of characters in a string in JavaScript?

June 17, 2022 beroza

What are the differences between IP address 0.0.0.0 and 127.0.0.1?

December 4, 2019 beroza

Why Upokary?

Upokary.com is a useful application in everyday life. It provides very handy information regarding every aspect of life. Each and every tip of upokary.com is meant to make life better.

Upokary tools

  • Youtube thumbnail
  • Youtube video downloader

Useful Links

  • Handy code
  • Technology
  • People
  • Programming
  • Quote
  • Travel
  • WordPress
  • IELTS
  • Kids

Pages

  • Sitemap
  • Privacy policy
  • About us
  • Contact us

Support

For any kind of query or question please drop a message in the following email: upokary@gmail.com
Copyright © 2025 Upokary. All rights reserved.