mirror of
https://github.com/apotdevin/thunderhub.git
synced 2025-02-22 06:21:37 +01:00
* chore: 🔧 strict enable wip * Improve typings, add type dependencies (#97) We improve the TypeScript situation by enabling `noImplicitAny`. This leads to a bunch of errors, as expected. We fix some of these by installing the correct types, and some are fixed manually by an educated guess. There are still a lot left, and these seem to be a big mix of lacking types for the `ln-service` dependency and potential bugs. * Strict null (#100) * chore: 🔧 enable strict-null * chore: 🔧 more checks * chore: 🔧 some fixes * chore: 🔧 more types * chore: 🔧 more types * chore: 🔧 more types * chore: 🔧 more types * chore: 🔧 more types * chore: 🔧 more types * chore: 🔧 more types * chore: 🔧 enable strict * fix: 🐛 input * fix: 🐛 forward report * fix: 🐛 chat sending * fix: 🐛 chat bubble input Co-authored-by: Torkel Rogstad <torkel@rogstad.io>
24 lines
760 B
TypeScript
24 lines
760 B
TypeScript
import { getErrorMsg } from './helpers';
|
|
import { logger } from './logger';
|
|
|
|
export const to = async <T>(promise: Promise<T>) => {
|
|
return promise
|
|
.then(data => data)
|
|
.catch(err => {
|
|
logger.error('%o', err);
|
|
throw new Error(getErrorMsg(err));
|
|
});
|
|
};
|
|
|
|
/*
|
|
* This is hard/impossible to type correctly. What we are describing
|
|
* here is a set of two states: either we have a result and no error,
|
|
* _or_ we have no result and an error. Unfortunately TypeScript is
|
|
* not able to infer this correctly...
|
|
* https://github.com/microsoft/TypeScript/issues/12184
|
|
*/
|
|
export const toWithError = async <T>(promise: Promise<T>) => {
|
|
return promise
|
|
.then(data => [data, undefined] as const)
|
|
.catch(err => [undefined, err] as const);
|
|
};
|