Skip to content

Commit 28c35c1

Browse files
committed
feat(common): typed decorators through generics
1 parent 0b89142 commit 28c35c1

1 file changed

Lines changed: 1 addition & 43 deletions

File tree

packages/common/decorators/http/create-route-param-metadata.decorator.ts

Lines changed: 1 addition & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -39,49 +39,7 @@ type Unpacked<T> = T extends (infer U)[]
3939
*
4040
* @param factory
4141
*/
42-
export function createParamDecorator(
43-
factory: CustomParamFactory,
44-
enhancers: ParamDecoratorEnhancer[] = [],
45-
): (
46-
...dataOrPipes: (Type<PipeTransform> | PipeTransform | any)[]
47-
) => ParameterDecorator {
48-
const paramtype = uuid();
49-
return (
50-
data?,
51-
...pipes: (Type<PipeTransform> | PipeTransform)[]
52-
): ParameterDecorator => (target, key, index) => {
53-
const args =
54-
Reflect.getMetadata(ROUTE_ARGS_METADATA, target.constructor, key) || {};
55-
56-
const isPipe = (pipe: any) =>
57-
pipe &&
58-
((isFunction(pipe) &&
59-
pipe.prototype &&
60-
isFunction(pipe.prototype.transform)) ||
61-
isFunction(pipe.transform));
62-
63-
const hasParamData = isNil(data) || !isPipe(data);
64-
const paramData = hasParamData ? data : undefined;
65-
const paramPipes = hasParamData ? pipes : [data, ...pipes];
66-
67-
Reflect.defineMetadata(
68-
ROUTE_ARGS_METADATA,
69-
assignCustomMetadata(
70-
args,
71-
paramtype,
72-
index,
73-
factory,
74-
paramData,
75-
...(paramPipes as PipeTransform[]),
76-
),
77-
target.constructor,
78-
key,
79-
);
80-
enhancers.forEach(fn => fn(target, key, index));
81-
};
82-
}
83-
84-
export function createGenericParamDecorator<T>(
42+
export function createParamDecorator<T>(
8543
factory: CustomParamFactory,
8644
enhancers: ParamDecoratorEnhancer[] = [],
8745
): (

0 commit comments

Comments
 (0)