LarpixClient/electron/node_modules/ensure-error/index.d.ts
olcxja cca8b02fea
Some checks failed
Android Build / publish (push) Successful in 33s
Linux Build / publish (push) Failing after 25s
Update gitignore (sorry)
2026-05-10 14:02:17 +02:00

36 lines
907 B
TypeScript

declare namespace ensureError {
interface NonError extends Error {
name: 'NonError';
}
}
// IfAny<T, ThenType, ElseType> resolves to ThenType if T is `any` and resolves to ElseType otherwise
// https://stackoverflow.com/a/49928360/4135063
type IfAny<T, ThenType, ElseType> = 0 extends (1 & T) ? ThenType : ElseType;
/**
Ensures a value is a valid error by making it one if not.
If `input` is an `Error`, any missing `Error` properties will be added.
If it's not an `Error`, `input` is converted to an `Error`.
@example
```
import ensureError = require('ensure-error');
const error = new TypeError('🦄');
error.name = '';
console.log(error.name);
//=> ''
console.log(ensureError(error).name);
//=> 'TypeError'
console.log(ensureError(10));
//=> [NonError: 10]
```
*/
declare function ensureError<T>(input: T): IfAny<T, Error, T extends Error ? T : ensureError.NonError>;
export = ensureError;