Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/ayecue/overload
Method overloading via decorators
https://github.com/ayecue/overload
overloading
Last synced: 15 days ago
JSON representation
Method overloading via decorators
- Host: GitHub
- URL: https://github.com/ayecue/overload
- Owner: ayecue
- Created: 2024-09-19T22:25:50.000Z (4 months ago)
- Default Branch: main
- Last Pushed: 2024-09-21T00:45:13.000Z (4 months ago)
- Last Synced: 2024-11-30T20:48:31.384Z (about 2 months ago)
- Topics: overloading
- Language: TypeScript
- Homepage:
- Size: 208 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# overload
[![overload](https://circleci.com/gh/ayecue/overload.svg?style=svg)](https://circleci.com/gh/ayecue/overload)
Pseudo overload via decorators.
## Installation
```sh
npm install --save pseudo-overload
```## Example
```ts
import { z } from 'zod';
import { OverloadConstructor, Overload } from 'pseudo-overload';@OverloadConstructor(
[[z.string(), z.number()], function (str: string, num: number) {
this.propertyA = `${str} - ${num}`;
this.propertyB = 'empty';
}],
[[], function () {
this.propertyA = 'empty';
this.propertyB = 'provided no params'
}]
)
export class MyTestClass {
propertyA: string;
propertyB: string;constructor();
constructor(str: number, num: string);
constructor(str: string, num: number);
constructor(...args: any[]) { }foo(str: number): string;
foo(str: string): string;
@Overload(
[[z.string()], function (str: string) {
return `A String ${str}`;
}],
)
foo(...args: any[]): any { }bar(str: string, num?: number): string;
@Overload(
[[z.string(), z.number()], function (str: string, num: number) {
return `A String ${str} And A Number ${num}`;
}],
[[z.string()], function (str: string | null) {
return `A String ${str}`;
}],
)
bar(...args: any[]): any { }
}
```