All files / solid/src types.ts

0% Statements 0/0
0% Branches 0/0
0% Functions 0/0
0% Lines 0/0

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108                                                                                                                                                                                                                       
import type { JSX } from 'solid-js';
 
export type StateRef<T> = {
  value: T;
};
 
export type ConstantRef<T> = {
  get value(): T;
};
 
export type VariableRef<T> = {
  get value(): T;
  set value(value: T);
};
 
/**
 * A type alias to create a writable prop inference.
 */
export type Bindable<T> = {
  get value(): T;
  set value(value: T);
};
 
/**
 * A type alias to create a writable prop inference.
 */
export type BindableProp<T> = T | Bindable<T>;
 
export type BindableProps<P> = {
  [K in keyof P]: P[K] extends Bindable<infer T> | undefined ? BindableProp<T> : P[K];
};
 
/**
 * Extracts keys from type P where the value is not a Bindable or undefined
 * Used to identify readonly properties in a component
 *
 * @template P - The props type to extract keys from
 */
export type ReadOnlyPropKeys<P> = {
  [K in keyof P]: P[K] extends Bindable<unknown> | undefined ? never : K;
}[keyof P];
 
/**
 * Extracts keys from type P where the value is a Bindable or undefined
 * Used to identify writable properties in a component
 *
 * @template P - The props type to extract keys from
 */
export type WritablePropKeys<P> = {
  [K in keyof P]: P[K] extends Bindable<unknown> | undefined ? K : never;
}[keyof P];
 
/**
 * Creates a type with all properties of P marked as readonly
 *
 * @template P - The props type to make readonly
 */
export type ReadonlyProps<P> = {
  readonly [K in keyof P]: P[K];
};
 
/**
 * Creates a type with only the Bindable properties of P converted to their bound type
 * Non-Bindable properties are mapped to 'never'
 *
 * @template P - The props type to extract writable properties from
 */
export type WritableProps<P> = {
  [K in keyof P]: P[K] extends Bindable<infer T> | undefined ? T : never;
};
 
/**
 * Extended component props that include an $omit method for omitting specific keys.
 *
 * @template P - The base props type
 * @property $omit - A method that returns a new object with specified keys omitted
 */
export type BindableComponentProps<P> = Omit<ReadonlyProps<P>, WritablePropKeys<P>> &
  Omit<WritableProps<P>, ReadOnlyPropKeys<P>> & {
    /**
     * Creates a new object with specified keys omitted from the original props.
     * If no keys are provided, returns a copy of all props.
     *
     * @template K - The keys to omit from props
     * @param keys - Optional array of keys to omit
     * @returns A new object with specified keys removed
     */
    $omit<K extends keyof P>(keys?: Array<K>): Omit<P, K>;
 
    /**
     * Creates a new object containing only the specified keys from the original props.
     * If no keys are provided, returns an empty object.
     *
     * @template K - The keys to pick from props
     * @param keys - Optional array of keys to include
     * @returns A new object with only the specified keys
     */
    $pick<K extends keyof P>(keys?: Array<K>): Pick<P, K>;
  } & {};
 
export type HTMLAttributes<E> = JSX.HTMLAttributes<E>;
export type EventHandler<T extends HTMLElement, E extends Event> = JSX.EventHandler<T, E>;
 
export type InputHTMLAttributes<E extends HTMLElement> = Omit<JSX.InputHTMLAttributes<E>, 'onInput' | 'oninput'> & {
  onInput?: EventHandler<E, InputEvent>;
  oninput?: EventHandler<E, InputEvent>;
};