- What does it do ?
- Compatibility
- Dependencies
- Installation
- How to use
- Incorrect usages
- Credits
- License
Provide a simple implementation of the Nullable<T>
type which allow a value to be either T
or null
.
TypeScript | EcmaScript |
---|---|
>= 2.8.0 | >= ES2015 |
This package is dependencies-free.
Nothing more than :
npm i -S @sefr/nullable
✅ 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
❌ 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;
}
}
- Developed with the awesome TypeScript
This software is available under the MIT License. See the LICENSE file for more informations.