1.0.2 ā€¢ Published 8 months ago

@sefr/nullable v1.0.2

Weekly downloads
-
License
MIT
Repository
github
Last release
8 months ago

@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 šŸ”§

TypeScriptEcmaScript
>= 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

1.0.2

8 months ago

1.0.1

10 months ago

1.0.0

1 year ago