Hacker Timesnew | past | comments | ask | show | jobs | submitlogin

The discriminated union pattern is better [1]

    type Success<T> = { type: 'success', value: T};
    type Error = { type: 'error', value: string };
    type Result<T> = Success<T> | Error;

    if (result.type === 'error') {
      result.error;
    } else {
      result.value;
    }
[1] https://www.typescriptlang.org/docs/handbook/advanced-types....


Consider applying for YC's Summer 2026 batch! Applications are open till May 4

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: