Friday, May 9, 2025
Latest:
  • Der kleine Vogel und die Sonne
  • German alphabet pronunciation
  • Command design pattern
  • German words with gender
  • When to use einen and keinen in German?
Upokary

Upokary

Quality information

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

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

Published: December 1, 2021JavaScript, 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

How to set custom user-agent in Google chrome?

June 1, 2020 beroza

Average Salary Excluding the Minimum and Maximum Salary

May 28, 2023 beroza

Write a program to determine color of a chessboard square

June 8, 2022 beroza

Warning: Each child in a list should have a unique “key” prop

March 25, 2019 beroza

What are log4j logging hierarchical order in Java?

November 19, 2019 beroza

Error establishing a database connection WordPress on Mac

August 27, 2019 beroza

Learn Kubernetes basics.

May 3, 2020 beroza

When to use mein vs meine, dein vs deine, Ihr vs Ihre in German language

October 24, 2024 beroza

How to load ads using Single Request Architecture in Google Publisher Tag?

June 30, 2021 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

Languages

  • EnglishEnglish
  • বাংলাবাংলা

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.