Types
The npm package exports these utility types:
Types
export type FirstArgOf<T> = T extends (first: infer FirstArgument, ...args: any[]) => any
? FirstArgument
: never;
export type SecondArgOf<T> = T extends (
first: any,
second: infer SecondArgument,
...args: any[]
) => any
? SecondArgument
: never;
/**
* Thank you Matt Pocock
* {@link https://twitter.com/mattpocockuk/status/1622730173446557697}
*/
export type Prettify<T> = {
[K in keyof T]: T[K];
} & {};
export type Optional<T> = T | undefined;
The arg inferral types can be useful in svelte for example when storing transitions / actions and their params in variables like so:
Example
import type { SecondArgOf } from '$lib/types';
import { fly } from 'svelte/transition';
export const ROUTE_TRANSITION = fly;
export const ROUTE_TRANSITION_PARAMS: SecondArgOf<typeof ROUTE_TRANSITION> = {
// Infers FlyParams
duration: 250,
opacity: 0,
x: 300
};
The Prettify-type is just cool.