Skip to content

Commit

Permalink
fixed bugs in propertiesAggregation.ts
Browse files Browse the repository at this point in the history
  • Loading branch information
LCcodder committed Oct 25, 2024
1 parent 337f5c7 commit b62350d
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 4 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "typing-assets",
"version": "2.1.3",
"version": "2.1.4",
"description": "Additional typing assets and helpers for better TypeScript experience",
"main": "build/index.js",
"types": "build/index.d.ts",
Expand Down
10 changes: 8 additions & 2 deletions src/functions/propertiesAggregation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@
*/
export const excludeProperties = <TSource, TProp extends keyof TSource> (source: TSource, ...args: TProp[]): Omit<TSource, TProp> => {
for (const key in source) {
if ([...args].includes(key as string as TProp )) delete source[key]
if ([...args].includes(key as string as TProp )) {
source[key] = undefined as any
delete source[key]
}
}
return source
}
Expand All @@ -20,7 +23,10 @@ export const excludeProperties = <TSource, TProp extends keyof TSource> (source:
*/
export const pickProperties = <TSource, TProp extends keyof TSource>(source: TSource, ...args: TProp[]): Pick<TSource, TProp> => {
for (const key in source) {
if (![...args].includes(key as string as TProp )) delete source[key]
if (![...args].includes(key as string as TProp )) {
source[key] = undefined as any
delete source[key]
}
}
return source
}
12 changes: 11 additions & 1 deletion src/utilityTypes/utility.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,15 @@ export declare type ExcludeActual<T> = T extends object ? {
[P in keyof T]: ExcludeActual<T[P]>
} : Exclude<T, string | number | T[] | symbol | bigint>


/**
* @description Returns actual return type of function, resolving all promises and excluding nullables
*/
export declare type ActualReturnType<T> = T extends (args: any[]) => Promise<any> ? ExcludeNullable<Awaited<ReturnType<T>>> : T extends (args: any[]) => any ? ExcludeNullable<ReturnType<T>> : never

/**
* @description Changes type of property(es) to provided type primitive
* @T Providing type
* @P Property which type will be replaced
* @C Replacing type
*/
export type ChangePropertyType<T, P extends keyof T, C> = Omit<T, P> & { [P in keyof T]: C }

0 comments on commit b62350d

Please sign in to comment.