Socket
Socket
Sign inDemoInstall

@shopify/useful-types

Package Overview
Dependencies
Maintainers
13
Versions
65
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@shopify/useful-types - npm Package Compare versions

Comparing version 1.2.4 to 1.3.0

6

CHANGELOG.md

@@ -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 @@

3

dist/types.d.ts
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>

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc