Skip to content

Commit

Permalink
fix(express): remove generic from ClassOrMethodDecorator interface
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremyben committed Oct 3, 2021
1 parent 425f5ff commit b450227
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 40 deletions.
4 changes: 2 additions & 2 deletions express/__tests__/send.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -226,9 +226,9 @@ describe('buffers', () => {
})

describe('class decorator', () => {
const JsonRouter = (path: string | RegExp): Decorator.Router & Decorator.Send<'class'> => {
const JsonRouter = (path: string | RegExp): Decorator.Router & Decorator.Send => {
return (target) => {
Router(path)(target)
Router(path)(target as Function)
Send({ json: true, undefinedStatus: 404 })(target)
}
}
Expand Down
47 changes: 9 additions & 38 deletions express/src/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,58 +89,39 @@ export namespace Decorator {
* Equivalent to a union of `ClassDecorator` and `MethodDecorator`.
* @public
*/
export type Use<T extends ClassOrMethodUnion = 'class|method'> = ClassOrMethodDecorator<T> & {
__expressUse?: never
}
export type Use = ClassOrMethodDecorator & { __expressUse?: never }

/**
* Used for `@Catch` decorator.
* Equivalent to a union of `ClassDecorator` and `MethodDecorator`.
* @public
*/
export type Catch<T extends ClassOrMethodUnion = 'class|method'> = ClassOrMethodDecorator<T> & {
__expressCatch?: never
}
export type Catch = ClassOrMethodDecorator & { __expressCatch?: never }

/**
* Used for `@Send` decorator.
* Equivalent to a union of `ClassDecorator` and `MethodDecorator`.
* @public
*/
export type Send<T extends ClassOrMethodUnion = 'class|method'> = ClassOrMethodDecorator<T> & {
__expressSend?: never
}
export type Send = ClassOrMethodDecorator & { __expressSend?: never }

/**
* Used for `@Send.Dont` decorator.
* Equivalent to a union of `ClassDecorator` and `MethodDecorator`.
* @public
*/
export type DontSend<T extends ClassOrMethodUnion = 'class|method'> = ClassOrMethodDecorator<T> & {
__expressDontSend?: never
}
export type DontSend = ClassOrMethodDecorator & { __expressDontSend?: never }
}

/**
* @public
*/
type ClassOrMethodUnion = 'class' | 'method' | 'class|method'

/**
* Generic decorator type to choose beetween `ClassDecorator`, `MethodDecorator`, or both.
* @public
*/
type ClassOrMethodDecorator<T extends ClassOrMethodUnion = 'class|method'> = T extends 'class'
? ClassDecorator
: T extends 'method'
? MethodDecorator
: T extends 'class|method'
? <TFunction extends Function>(
target: TFunction | Object,
propertyKey?: string | symbol,
descriptor?: TypedPropertyDescriptor<any>
) => any
: never
type ClassOrMethodDecorator = <TFunction extends Function>(
target: TFunction | Object,
propertyKey?: string | symbol,
descriptor?: TypedPropertyDescriptor<any>
) => any

/**
* @public
Expand All @@ -151,16 +132,6 @@ type PropertyOrMethodDecorator = (
descriptor?: TypedPropertyDescriptor<any>
) => any

/**
* @public
*/
type TypedDescriptor<T> = {
enumerable?: boolean
configurable?: boolean
writable?: boolean
value?: T
}

/**
* Defines a class type. Does the opposite of built-in `InstanceType`.
* @public
Expand Down

0 comments on commit b450227

Please sign in to comment.