Files
eas-cli/scripts/src/nullthrows.ts
T
Dominik Sokal 04a8b08f59 [ENG-4579][scripts] convert to ESM (#1192)
* upgrade typescript to 4.7.4

* [scripts] add extensions to imports

* [scripts] configure as ESM

* [scripts] fix after converting to ESM

* [scripts] fix lint

* [scripts] require node >= 14.16

* [scripts] add node: protocol

* add scripts/build to .gitignore

* [scripts] add typecheck script

* add workflow for testing scripts

* address PR feedback
2022-07-04 11:50:57 +02:00

10 lines
329 B
TypeScript

export function nullthrows<T>(value: T | null | undefined, message?: string): T {
if (value !== null && value !== undefined) {
return value;
}
const error = new Error(message !== undefined ? message : `Got unexpected ${value}`);
(error as any).framesToPop = 1; // Skip nullthrows's own stack frame.
throw error;
}