Friday, January 30, 2026
Latest:
  • Wichtige wörter für B1 prüfung
  • 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?
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

How to install or setup WordPress multisite?

December 4, 2019 beroza

The following PHP extension is missing: curl AMP WordPress

January 16, 2020 beroza

What is microservice? What are the properties of microservice?

June 18, 2020 beroza

How to compile TypeScript in command line?

April 26, 2022 beroza

Parsing error: Adjacent JSX elements must be wrapped in an enclosing tag. Did you want a JSX fragment

August 23, 2019 beroza

Write a Program to Find Three Consecutive Odds

May 15, 2023 beroza

Insert character after every n characters

February 11, 2022 beroza

Uncaught TypeError: Cannot read property ‘x’ of undefined

May 17, 2019 beroza

Warning: mysqli_connect(): (HY000/2002): No such file or directory

April 29, 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

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.