This post explains the differences very well. They are the same in TypeScript as in JavaScript.

As for what you should use: You may define that on your own. You may use either, just be aware of the differences and it might make sense to be consistent.

The TypeScript coding style guide for the TypeScript source code (not an official "how to use TypeScript" guide) states that you should always use undefined and not null: Typescript Project Styleguide.

Answer from Spitzbueb on Stack Overflow
🌐
Reddit
reddit.com › r/typescript › undefined vs null
r/typescript on Reddit: Undefined vs null
February 27, 2023 -

Since switching to TypeScript I have been using a lot of optional properties, for example:

type store = {
  currentUserId?: string
}

function logout () {
  store.currentUserId = undefined
}

However my coworkers and I have been discussing whether null is a more appropriate type instead of undefined, like this:

type store = {
  currentUserId: string | null
}

function logout () {
  store.currentUserId = null
}

It seems like the use of undefined in TypeScript differs slightly from in Javascript.

Do you guys/girls use undefined or null more often? And, which of the examples above do you think is better?

🌐
GitBook
basarat.gitbook.io › typescript › recap › null-undefined
Null vs. Undefined | TypeScript Deep Dive
Something hasn't been initialized : undefined. Something is currently unavailable: null.
🌐
DEV Community
dev.to › sduduzog › null-vs-undefined-what-to-choose-what-to-use-11g
null vs undefined? What to choose? What to use? - DEV Community
August 23, 2023 - When a javascript object is being serialized, all undefined properties are discarded, remember 'undefined' means a property is yet to be assigned a value. But null on the other hand is known by JSON as its a valid JSON data type
🌐
W3Schools
w3schools.com › typescript › typescript_null.php
TypeScript Null & Undefined
let value: string | undefined | null = null; value = 'hello'; value = undefined; Try it Yourself » · When strictNullChecks is enabled, TypeScript requires values to be set unless undefined is explicitly added to the type.
🌐
TypeScript
typescriptlang.org › docs › handbook › release-notes › typescript-2-0.html
TypeScript: Documentation - TypeScript 2.0
TypeScript has two special types, Null and Undefined, that have the values null and undefined respectively.
🌐
DEV Community
dev.to › typescripttv › what-is-the-difference-between-null-and-undefined-5h76
What is the difference between null and undefined? - DEV Community
March 12, 2023 - The convention in TypeScript is that undefined values have not been defined yet, whereas null values indicate intentional absence of a value.
🌐
Medium
medium.com › @o_o_o › null-vs-undefined-can-i-use-only-one-a3b7db5468f2
null vs. undefined: Can I use only one? | by OOO | Medium
March 29, 2022 - In older browsers, it was possible to overwrite undefined because it is not a reserved word unlike null. So it leads to side effect if you do this: But in modern browsers (JavaScript 1.8.5 / Firefox 4+), undefined is a non-configurable, non-writable property, per the ECMAScript 5 specification. So it’s no longer a problem if you’re using “modern browser”. And there’re already some guys doing it: Typescript team only uses undefined and Douglas Crockford stopped using null.
Find elsewhere
🌐
Tektutorialshub
tektutorialshub.com › home › typescript › null vs undefined in typescript
Null Vs Undefined in TypeScript - Tektutorialshub
March 15, 2023 - It means that a variable has been declared but has not yet been assigned a value. The value null indicates that you know that the field does not have a value. It is an intentional absence of value.
🌐
Mikevosseller
blog.mikevosseller.com › 2022 › 10 › 03 › when-to-use-null-vs-undefined-with-optional-parameters-in-typescript.html
When to use null vs undefined with optional parameters in TypeScript | mpv’s little blog
October 4, 2022 - An undefined value may indicate the value should not be updated. If an argument isn’t needed at every call site I’ll make it optional OR give it a default value if there is one that makes sense. If an argument should accept null then I’ll allow null by adding | null to its type.
🌐
GitHub
github.com › microsoft › TypeScript › issues › 9653
Guidelines for choosing between `null` and `undefined` with `strictNullChecks` · Issue #9653 · microsoft/TypeScript
July 12, 2016 - Whenever you want to make a type optional you have to choose what value to use for the missing values: undefined: Has the benefit that is already there when you don't write anything. lib.d.ts contains 12 references of | undefined. null: ...
Published   Jul 12, 2016
🌐
TutorialsPoint
tutorialspoint.com › home › typescript › typescript: null vs undefined
TypeScript: Null vs Undefined
December 18, 2016 - In such cases, you can use the null or undefined data types to represent the absence of values. In TypeScript, 'null' is a primitive value, which represents the no value assigned to the variable.
🌐
DevGenius
blog.devgenius.io › typescript-when-to-use-null-undefined-or-empty-array-d45244ffc565
Typescript: when to use null, undefined or empty array? | by Aleksei Jegorov | Dev Genius
May 13, 2022 - Something hasn’t been initialized, not assigned value: use undefined. Something is currently unavailable: use null.
🌐
GeeksforGeeks
geeksforgeeks.org › how-to-check-null-and-undefined-in-typescript
How to check null and undefined in TypeScript ? - GeeksforGeeks
August 1, 2024 - A variable is undefined when it's not assigned any value after being declared. Null refers to a value that is either empty or doesn't exist. null means no value. To make a variable null we must assign null value to it as by default in typescript ...
🌐
Medium
basarat.medium.com › null-vs-undefined-in-typescript-land-dc0c7a5f240a
`null` vs. `undefined` in TypeScript land | by BASARAT | Medium
January 25, 2017 - If a falsy value is a valid value (e.g. ‘’, false, 0) then filter out both null and undefined with `== undefined` as it works with `null` and `undefined` but not for other falsy values. For default values to functions let the TypeScript compiler do the `undefined` check for you.
🌐
DEV Community
dev.to › jefersoneiji › undefined-vs-null-in-typescript-whats-the-difference-cgp
Undefined vs Null in TypeScript: What’s the Difference? - DEV Community
3 days ago - By default, variables can be undefined but not null unless you adjust your TypeScript configuration (strictNullChecks).
🌐
Zipy
zipy.ai › blog › debug-typescript-null-or-undefined-value-errors
Solving Typescript Null & Undefined Errors: Expert Tips
February 28, 2024 - This design choice is inherited from JavaScript, providing flexibility in indicating the absence of a value (null) versus an uninitialized variable (undefined). ... Zipy offers proactive error monitoring and session replay capabilities, allowing ...