@shopify/useful-types
Advanced tools
Comparing version
@@ -8,4 +8,8 @@ # Changelog | ||
<!-- ## [Unreleased] --> | ||
## [2.2.0] - 2019-06-12 | ||
### Added | ||
- Added the `ConstructorArguments`, `ConstructorArgumentAtIndex`, and `FirstConstructorArgument` type aliases | ||
## [2.1.4] - 2019-01-27 | ||
@@ -12,0 +16,0 @@ |
@@ -32,3 +32,8 @@ export declare type ThenType<T> = T extends Promise<infer U> ? U : T; | ||
export declare type ExtendedWindow<T> = Window & typeof globalThis & T; | ||
export declare type ConstructorArguments<T> = T extends { | ||
new (...args: infer U): any; | ||
} ? U : never; | ||
export declare type ConstructorArgumentAtIndex<T, I extends keyof ConstructorArguments<T>> = ConstructorArguments<T>[I]; | ||
export declare type FirstConstructorArgument<T> = ConstructorArgumentAtIndex<T, 0>; | ||
export {}; | ||
//# sourceMappingURL=types.d.ts.map |
{ | ||
"name": "@shopify/useful-types", | ||
"version": "2.1.5", | ||
"version": "2.2.0", | ||
"license": "MIT", | ||
@@ -5,0 +5,0 @@ "description": "A few handy TypeScript types", |
@@ -44,2 +44,26 @@ # `@shopify/useful-types` | ||
- `ConstructorArgumentAtIndex<T, Index>`: Resolves to the type of the argument of the passed class's constructor 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`. | ||
```tsx | ||
class SomeClass { | ||
constructor(floop: string, doop: number) { | ||
console.log(floop); | ||
} | ||
} | ||
type DoopType = ConstructorArgument<typeof SomeClass, 1>; // number | ||
``` | ||
- `FirstConstructorArgument<T>`: Resolves to the type of the first argument to the passed class's constructor. This is shorthand for `ConstructorArgumentAtIndex<T, 0>`. | ||
```ts | ||
class SomeClass { | ||
constructor(floop: string) { | ||
console.log(floop); | ||
} | ||
} | ||
type DoopType = FirstConstructorArgument<typeof SomeClass>; // string | ||
``` | ||
- `ArrayElement<T>`: When `T` is an array, resolves to the type contained within the array. | ||
@@ -46,0 +70,0 @@ |
Sorry, the diff of this file is not supported yet
11095
16.83%42
13.51%108
28.57%