-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(types):
ClassDecorator
, MethodDecorator
Signed-off-by: Lexus Drumgold <[email protected]>
- Loading branch information
1 parent
01f8e6c
commit 514e5fc
Showing
8 changed files
with
120 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
/** | ||
* @file Type Tests - ClassDecorator | ||
* @module tutils/types/tests/unit-d/ClassDecorator | ||
*/ | ||
|
||
import type Vehicle from '#fixtures/types/vehicle' | ||
import type Class from '../class' | ||
import type TestSubject from '../decorator-class' | ||
|
||
describe('unit-d:types/ClassDecorator', () => { | ||
type T = Class<Vehicle, [vin: Vehicle['vin']]> | ||
|
||
it('should be callable with [T]', () => { | ||
expectTypeOf<TestSubject<T>>().parameters.toEqualTypeOf<[T]>() | ||
}) | ||
|
||
it('should return T | void', () => { | ||
expectTypeOf<TestSubject<T>>().returns.toEqualTypeOf<T | void>() | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
/** | ||
* @file Type Tests - MethodDecorator | ||
* @module tutils/types/tests/unit-d/MethodDecorator | ||
*/ | ||
|
||
import type Vehicle from '#fixtures/types/vehicle' | ||
import type { PropertyDescriptor } from '#src/interfaces' | ||
import type Class from '../class' | ||
import type TestSubject from '../decorator-method' | ||
import type Fn from '../fn' | ||
import type OwnPropertyKey from '../property-key-own' | ||
|
||
describe('unit-d:types/MethodDecorator', () => { | ||
type T = Fn<[vin: Vehicle['vin']], Vehicle> | ||
type U = Class<Vehicle, [vin: Vehicle['vin']]> | ||
|
||
it('should be callable with [U, OwnPropertyKey, PropertyDescriptor<T>]', () => { | ||
// Arrange | ||
type Expect = [U, OwnPropertyKey, PropertyDescriptor<T>] | ||
|
||
// Expect | ||
expectTypeOf<TestSubject<T, U>>().parameters.toEqualTypeOf<Expect>() | ||
}) | ||
|
||
it('should return PropertyDescriptor<T> | void', () => { | ||
// Arrange | ||
type Expect = PropertyDescriptor<T> | void | ||
|
||
// Expect | ||
expectTypeOf<TestSubject<T>>().returns.toEqualTypeOf<Expect>() | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
/** | ||
* @file Type Definitions - ClassDecorator | ||
* @module tutils/types/ClassDecorator | ||
*/ | ||
|
||
import type Constructor from './constructor' | ||
import type AbstractConstructor from './constructor-abstract' | ||
|
||
/** | ||
* A class decorator. | ||
* | ||
* @see https://www.typescriptlang.org/docs/handbook/decorators.html#class-decorators | ||
* | ||
* @template T - Class type | ||
* | ||
* @param {T} target - Class declaration | ||
* @return {T | void} Class declaration or `undefined` | ||
*/ | ||
type ClassDecorator<T extends AbstractConstructor<any> = Constructor<any>> = ( | ||
target: T | ||
) => T | void | ||
|
||
export type { ClassDecorator as default } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
/** | ||
* @file Type Definitions - MethodDecorator | ||
* @module tutils/types/MethodDecorator | ||
*/ | ||
|
||
import type { PropertyDescriptor } from '#src/interfaces' | ||
import type DecoratorTarget from './decorator-target' | ||
import type Fn from './fn' | ||
import type OwnPropertyKey from './property-key-own' | ||
|
||
/** | ||
* A method decorator. | ||
* | ||
* @see {@linkcode DecoratorTarget} | ||
* @see https://www.typescriptlang.org/docs/handbook/decorators.html#method-decorators | ||
* | ||
* @template T - Property descriptor value type | ||
* @template U - Class constructor or instance type | ||
* | ||
* @param {U} target - Class declaration or prototype | ||
* @param {OwnPropertyKey} key - Method name | ||
* @param {PropertyDescriptor<T>} descriptor - Property descriptor for `key` | ||
* @return {PropertyDescriptor<T> | void} Property descriptor or `undefined` | ||
*/ | ||
type MethodDecorator< | ||
T extends Fn = Fn, | ||
U extends DecoratorTarget = DecoratorTarget | ||
> = ( | ||
target: U, | ||
key: OwnPropertyKey, | ||
descriptor: PropertyDescriptor<T> | ||
) => PropertyDescriptor<T> | void | ||
|
||
export type { MethodDecorator as default } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters