Sunday, October 11, 2026
Latest:
  • Präsentation für b1
  • Verb “werden” Konjugation
  • In German, verb sein (to be) Konjunktion
  • Wichtige wörter für B1 prüfung
  • What are the main differences between ApplicationContext and BeanFactory?
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

Wi-Fi

What is Wi-Fi? What are the advantages and disadvantages of Wi-Fi?

June 15, 2022 Griza Paul

Find the Longest Balanced Substring of a Binary String

May 12, 2023 beroza

What are the new features of Java 11?

April 22, 2019 beroza

How to do a HTTP API call in ruby on rails?

July 16, 2020 beroza

How to check if an element is visible in the current viewport as we scroll?

July 8, 2020 beroza

Write a program to determine color of a chessboard square

June 8, 2022 beroza

What are the main differences between ApplicationContext and BeanFactory?

November 1, 2025 beroza

Useful yarn commands for developers

July 27, 2021 beroza

Programming tips for coding interview

June 17, 2023 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 © 2026 Upokary. All rights reserved.