https://github.com/berhalak/dressup
Typescript decorators
https://github.com/berhalak/dressup
typescript typescript-decorators typescript-library
Last synced: over 1 year ago
JSON representation
Typescript decorators
- Host: GitHub
- URL: https://github.com/berhalak/dressup
- Owner: berhalak
- License: mit
- Created: 2020-02-03T14:05:41.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2020-03-05T22:05:24.000Z (over 6 years ago)
- Last Synced: 2025-03-11T15:11:40.367Z (over 1 year ago)
- Topics: typescript, typescript-decorators, typescript-library
- Language: TypeScript
- Size: 10.7 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# dressup
Typescript decorators
``` ts
import { mix, decorate } from "dressup"
test('decorator demo', () => {
class Base {
constructor(private num: number = null) {
}
baseMethod() {
return this.num;
}
}
@decorate()
class Derive extends Base {
constructor(private inner: Base) {
super(null);
}
deriveMethod() {
return this.baseMethod() + 2;
}
}
const bob = new Derive(new Base(10));
expect(bob.baseMethod()).toBe(10);
expect(bob.deriveMethod()).toBe(12);
})
test('mix demo', () => {
class Rename {
rename(name: string) {
(this as any).name = name;
return this;
}
}
class Printable {
print() {
return (this as any).name;
}
}
class Model extends mix(Rename, Printable) {
name = "test";
}
expect(new Model().print()).toBe("test");
expect(new Model().rename("hello").print()).toBe("hello");
})
```