@helios-lang/type-utils
Advanced tools
Comparing version 0.1.5 to 0.1.6
{ | ||
"name": "@helios-lang/type-utils", | ||
"version": "0.1.5", | ||
"version": "0.1.6", | ||
"description": "Global utility types", | ||
@@ -5,0 +5,0 @@ "main": "src/index.js", |
@@ -7,3 +7,4 @@ declare global { | ||
export const None: null | ||
export function expectSome<T>(option: Option<T>, msg?: string): T | ||
export function isNone<T>(option: Option<T>): option is null | undefined | ||
export function isSome<T>(option: Option<T>): option is T |
@@ -8,7 +8,21 @@ /** | ||
* @template T | ||
* @param {Option<T>} opt | ||
* @param {Option<T>} option | ||
* @param {string} msg | ||
* @returns {T} | ||
*/ | ||
export function expectSome(option, msg = `unexpected ${option}`) { | ||
if (option !== null && option !== undefined) { | ||
return option | ||
} else { | ||
throw new Error(msg) | ||
} | ||
} | ||
/** | ||
* @template T | ||
* @param {Option<T>} option | ||
* @returns {opt is T} | ||
*/ | ||
export function isSome(opt) { | ||
return opt !== null && opt !== undefined | ||
export function isSome(option) { | ||
return option !== null && option !== undefined | ||
} | ||
@@ -18,7 +32,7 @@ | ||
* @template T | ||
* @param {Option<T>} opt | ||
* @param {Option<T>} option | ||
* @returns {opt is (null | undefined)} | ||
*/ | ||
export function isNone(opt) { | ||
return opt === null || opt === undefined | ||
export function isNone(option) { | ||
return option === null || option === undefined | ||
} |
3766
57