@sefr/nullable
TypeScript icon, indicating that this package has built-in type declarations

1.0.2 • Public • Published

@sefr/nullable ✨

What does it do ? 💡

Provide a simple implementation of the Nullable<T> type which allow a value to be either T or null.

Compatibility 🔧

TypeScript EcmaScript
>= 2.8.0 >= ES2015

Dependencies 🎱

This package is dependencies-free.

Installation 💾

Nothing more than :

npm i -S @sefr/nullable

How to use 📚

✅ Returning a success without content :

import { Nullable } from "@sefr/nullable";

function doSomething(condition: boolean): Nullable<string> {
    if (condition) {
		return "toto";
    } else {
		return null;
    }
}

const toto: Nullable<string> = doSomething(true);
console.log(toto); // "toto"
const titi: Nullable<string> = doSomething(false);
console.log(titi); // null

Incorrect usages ❌

❌ Returning undefined instead of null won't work at compilation time :

import { Nullable } from "@sefr/nullable";

function doSomething(condition: boolean): Nullable<string> {
	if (condition) {
		return "toto";
	} else {
		return undefined;
	}
}

Credits 📎

License 📜

This software is available under the MIT License. See the LICENSE file for more informations.

⬆️ Go back to top

Readme

Keywords

Package Sidebar

Install

npm i @sefr/nullable

Weekly Downloads

1

Version

1.0.2

License

MIT

Unpacked Size

5.98 kB

Total Files

9

Last publish

Collaborators

  • sefr