addons/components/Types.tsblame
View source
b69ab311/**
b69ab312 * Copyright (c) Meta Platforms, Inc. and affiliates.
b69ab313 *
b69ab314 * This source code is licensed under the MIT license found in the
b69ab315 * LICENSE file in the root directory of this source tree.
b69ab316 */
b69ab317
b69ab318export type TypeaheadResult = {
b69ab319 /** The display text of the suggestion */
b69ab3110 label: string;
b69ab3111
b69ab3112 /**
b69ab3113 * Additional details to show de-emphasized next to the display name.
b69ab3114 * If provided, this is shown visually instead of the value.
b69ab3115 */
b69ab3116 detail?: string;
b69ab3117
b69ab3118 /**
b69ab3119 * The literal value of the suggestion, placed literally as text into the commit message.
b69ab3120 * If `detail` is not provided, value is shown de-emphasized next to the display name.
b69ab3121 */
b69ab3122 value: string;
b69ab3123
b69ab3124 /**
b69ab3125 * An optional image url representing this result. Usually, a user avatar.
b69ab3126 */
b69ab3127 image?: string;
b69ab3128};
b69ab3129
b69ab3130/**
b69ab3131 * Remove particular keys from an object type:
b69ab3132 * ```
b69ab3133 * Without<{foo: string, bar: string, baz: number}, 'bar' | 'baz'> => {foo: string}
b69ab3134 * ```
b69ab3135 */
b69ab3136export type Without<T, U> = {[P in Exclude<keyof T, keyof U>]?: never};
b69ab3137
b69ab3138/**
b69ab3139 * Given two object types, return a type allowing keys from either one but not both
b69ab3140 * ```
b69ab3141 * ExclusiveOr({foo: string}, {bar: number}) -> allows {foo: 'a'}, {bar: 1}, but not {foo: 'a', bar: 1} or {}
b69ab3142 * ```
b69ab3143 */
b69ab3144export type ExclusiveOr<T, U> = T | U extends object
b69ab3145 ? (Without<T, U> & U) | (Without<U, T> & T)
b69ab3146 : T | U;