when.d.ts 1.1 KB

12345678910111213141516171819202122232425262728
  1. /**
  2. * @license
  3. * Copyright 2021 Google LLC
  4. * SPDX-License-Identifier: BSD-3-Clause
  5. */
  6. type Falsy = null | undefined | false | 0 | -0 | 0n | '';
  7. /**
  8. * When `condition` is true, returns the result of calling `trueCase()`, else
  9. * returns the result of calling `falseCase()` if `falseCase` is defined.
  10. *
  11. * This is a convenience wrapper around a ternary expression that makes it a
  12. * little nicer to write an inline conditional without an else.
  13. *
  14. * @example
  15. *
  16. * ```ts
  17. * render() {
  18. * return html`
  19. * ${when(this.user, () => html`User: ${this.user.username}`, () => html`Sign In...`)}
  20. * `;
  21. * }
  22. * ```
  23. */
  24. export declare function when<C extends Falsy, T, F = undefined>(condition: C, trueCase: (c: C) => T, falseCase?: (c: C) => F): F;
  25. export declare function when<C, T, F>(condition: C extends Falsy ? never : C, trueCase: (c: C) => T, falseCase?: (c: C) => F): T;
  26. export declare function when<C, T, F = undefined>(condition: C, trueCase: (c: Exclude<C, Falsy>) => T, falseCase?: (c: Extract<C, Falsy>) => F): C extends Falsy ? F : T;
  27. export {};
  28. //# sourceMappingURL=when.d.ts.map