@shopify/useful-types
Advanced tools
Comparing version 1.2.4 to 1.3.0
@@ -8,2 +8,8 @@ # Changelog | ||
## [1.3.0] | ||
### Added | ||
- Added the `ArgumentAtIndex` type ([#691](https://github.com/Shopify/quilt/pull/691)) | ||
## [1.1.0] | ||
@@ -10,0 +16,0 @@ |
import { ComponentType, HTMLAttributes } from 'react'; | ||
export declare type ThenType<T> = T extends Promise<infer U> ? U : T; | ||
export declare type Arguments<T> = T extends (...args: infer U) => any ? U : never; | ||
export declare type FirstArgument<T> = T extends ((arg: infer U) => any) ? U : never; | ||
export declare type ArgumentAtIndex<Func, Index extends keyof Arguments<Func>> = Arguments<Func>[Index]; | ||
export declare type FirstArgument<T> = ArgumentAtIndex<T, 0>; | ||
export declare type MaybeFunctionReturnType<T> = T extends (...args: any[]) => infer U ? U : never; | ||
@@ -6,0 +7,0 @@ export declare type ArrayElement<T> = T extends (infer U)[] ? U : never; |
{ | ||
"name": "@shopify/useful-types", | ||
"version": "1.2.4", | ||
"version": "1.3.0", | ||
"license": "MIT", | ||
@@ -5,0 +5,0 @@ "description": "A few handy TypeScript types", |
@@ -28,5 +28,14 @@ # `@shopify/useful-types` | ||
- `FirstArgument<T>`: Resolves to the type of the first argument to the passed function. Useful for cases where you wish to extract the type of arguments without actually exporting the argument types, and is a nice complement to TypeScript’s built-in `ReturnType`. | ||
- `ArgumentAtIndex<T, Index>`: Resolves to the type of the argument of the passed function at the passed index. Useful for cases where you wish to extract the type of arguments without actually exporting the argument types, and is a nice complement to TypeScript’s built-in `ReturnType`. | ||
```ts | ||
const func = (foo: Promise<any>, bar: string) => foo.then(() => bar); | ||
type Arg1 = ArgumentAtIndex<typeof func, 0>; // Promise<any> | ||
type Arg2 = ArgumentAtIndex<typeof func, 1>; // string | ||
type NotAnArg = ArgumentAtIndex<string, 0>; // never | ||
``` | ||
- `FirstArgument<T>`: Resolves to the type of the first argument to the passed function. This is shorthand for `ArgumentAtIndex<T, 0>`. | ||
```ts | ||
const func = (foo: Promise<any>) => foo.then(() => 'bar'); | ||
@@ -33,0 +42,0 @@ type Arg = FirstArgument<typeof func>; // Promise<any> |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
6873
35
92