1.0.2 ⢠Published 2 years ago
@sefr/nullable v1.0.2
@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/nullableHow 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); // nullIncorrect 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 š
- Developed with the awesome TypeScript
License š
This software is available under the MIT License. See the LICENSE file for more informations.
ā¬ļø Go back to top