Skip to content

Commit

Permalink
feat: add AsyncReturnType type
Browse files Browse the repository at this point in the history
  • Loading branch information
nmsn committed Jul 11, 2023
1 parent 363d8b7 commit 9475d9c
Showing 1 changed file with 18 additions and 8 deletions.
26 changes: 18 additions & 8 deletions src/types/index.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,5 @@
import { MutableRefObject } from 'react';

export declare type ValueOf<T> = T[keyof T];

export declare type ArrayElement<A> = A extends readonly (infer T)[] ? T : never;

export declare type GetKeyByValueType<T, Condition> = {
[K in keyof T]: T[K] extends Condition ? K : never;
}[keyof T];

export type TargetValue<T> = T | undefined | null;

export type TargetType = HTMLElement | Element | Window | Document;
Expand All @@ -16,3 +8,21 @@ export type BasicTarget<T extends TargetType = Element> =
| (() => TargetValue<T>)
| TargetValue<T>
| MutableRefObject<TargetValue<T>>;

// 获取对象值类型
export declare type ValueOf<T> = T[keyof T];

// 获取数组的值的类型
export declare type ArrayElement<A> = A extends readonly (infer T)[] ? T : never;

// 通过对象的值的类型获取 key 的类型
export declare type GetKeyByValueType<T, Condition> = {
[K in keyof T]: T[K] extends Condition ? K : never;
}[keyof T];

// 获取异步函数返回的结果
export declare type AsyncReturnType<T extends (...args: any) => any> = T extends (
...args: any
) => Promise<infer R>
? R
: any;

1 comment on commit 9475d9c

@vercel
Copy link

@vercel vercel bot commented on 9475d9c Jul 11, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

utils – ./

nmsn-utils.vercel.app
utils-git-main-nmsn.vercel.app
utils-nmsn.vercel.app

Please sign in to comment.