Exploring the Promise
type with an illustration:
interface Promise<T> {
then<TResult1 = T, TResult2 = never>(
onfulfilled?:
| ((value: T) => TResult1 | PromiseLike<TResult1>)
| undefined
| null,
onrejected?:
| ((reason: any) => TResult2 | PromiseLike<TResult2>)
| undefined
| null
): Promise<TResult1 | TResult2>;
catch<TResult = never>(
onrejected?:
| ((reason: any) => TResult | PromiseLike<TResult>)
| undefined
| null
): Promise<T | TResult>;
}
Could organizing the types for onfulfilled
and/or onrejected
into separate lines enhance the code's clarity. While not functional in its current state, here is a conceptual representation of what it could resemble:
interface Promise<T> {
type OnFulfilled =
| ((value: T) => TResult1 | PromiseLike<TResult1>)
| undefined
| null
type OnRejected =
| ((reason: any) => TResult2 | PromiseLike<TResult2>)
| undefined
| null
then<TResult1 = T, TResult2 = never>(
onfulfilled?: OnFulfilled,
onrejected?: OnRejected
): Promise<TResult1 | TResult2>;
catch<TResult = never>(
onrejected?: OnRejected
): Promise<T | TResult>;
}
Is there potential to create types similar to this structure to enhance the readability of types?