Comparing version 5.4.1 to 6.0.0-beta.0
@@ -5,2 +5,13 @@ # Changelog | ||
## [6.0.0-beta.0](https://github.com/tannerntannern/ts-mixer/compare/v5.4.1...v6.0.0-beta.0) (2021-06-24) | ||
### ⚠ BREAKING CHANGES | ||
* drop TS < 4.2 support | ||
### Features | ||
* add abstract mixin support ([1c4b306](https://github.com/tannerntannern/ts-mixer/commit/1c4b306bae62fa6319c74d1f3040c8aba0da2c28)) | ||
### [5.4.1](https://github.com/tannerntannern/ts-mixer/compare/v5.4.0...v5.4.1) (2021-04-30) | ||
@@ -7,0 +18,0 @@ |
@@ -29,2 +29,3 @@ "use strict"; | ||
for (const constructor of constructors) | ||
// @ts-ignore: potentially abstract class | ||
util_1.copyProps(this, new constructor(...args)); | ||
@@ -31,0 +32,0 @@ if (initFunctionName !== null && typeof this[initFunctionName] === 'function') |
@@ -318,2 +318,3 @@ /** | ||
for (const constructor of constructors) | ||
// @ts-ignore: potentially abstract class | ||
copyProps(this, new constructor(...args)); | ||
@@ -320,0 +321,0 @@ if (initFunctionName !== null && typeof this[initFunctionName] === 'function') |
@@ -12,7 +12,3 @@ /** | ||
*/ | ||
export declare type Class<CtorArgs extends any[] = any[], InstanceType = {}, StaticType = {}> = { | ||
new (...args: CtorArgs): InstanceType; | ||
} & { | ||
[K in keyof StaticType]: StaticType[K]; | ||
}; | ||
export declare type Class<CtorArgs extends any[] = any[], InstanceType = {}, StaticType = {}, IsAbstract = false> = (abstract new (...args: any[]) => InstanceType) & StaticType; | ||
export {}; |
{ | ||
"name": "ts-mixer", | ||
"version": "5.4.1", | ||
"version": "6.0.0-beta.0", | ||
"description": "A very small TypeScript library that provides tolerable Mixin functionality.", | ||
@@ -23,26 +23,26 @@ "main": "dist/cjs/index.js", | ||
"devDependencies": { | ||
"@commitlint/cli": "^11.0.0", | ||
"@commitlint/config-conventional": "^11.0.0", | ||
"@commitlint/cli": "^12.1.4", | ||
"@commitlint/config-conventional": "^12.1.4", | ||
"@rollup/plugin-typescript": "^8.2.1", | ||
"@types/chai": "^4.2.15", | ||
"@types/mocha": "^8.2.0", | ||
"@types/node": "^14.14.28", | ||
"@types/sinon": "^9.0.10", | ||
"@typescript-eslint/parser": "^4.15.1", | ||
"chai": "^4.3.0", | ||
"@types/chai": "^4.2.19", | ||
"@types/mocha": "^8.2.2", | ||
"@types/node": "^15.12.4", | ||
"@types/sinon": "^10.0.2", | ||
"@typescript-eslint/parser": "^4.27.0", | ||
"chai": "^4.3.4", | ||
"class-validator": "^0.13.1", | ||
"coveralls": "^3.1.0", | ||
"eslint": "^7.20.0", | ||
"eslint": "^7.29.0", | ||
"husky": "^4.2.5", | ||
"js-yaml": "^4.0.0", | ||
"mocha": "^8.3.0", | ||
"js-yaml": "^4.1.0", | ||
"mocha": "^9.0.1", | ||
"nyc": "14.1.1", | ||
"rimraf": "^3.0.2", | ||
"rollup": "^2.45.2", | ||
"rollup": "^2.52.1", | ||
"rollup-plugin-terser": "^7.0.2", | ||
"sinon": "^9.2.4", | ||
"standard-version": "^9.1.0", | ||
"ts-node": "^9.1.1", | ||
"tslib": "^2.2.0", | ||
"typescript": "^4.2.4", | ||
"sinon": "^11.1.1", | ||
"standard-version": "^9.3.0", | ||
"ts-node": "^10.0.0", | ||
"tslib": "^2.3.0", | ||
"typescript": "^4.3.4", | ||
"yarn-add-no-save": "^1.0.3" | ||
@@ -49,0 +49,0 @@ }, |
@@ -6,3 +6,3 @@ # ts-mixer | ||
[build-link]: https://github.com/tannerntannern/ts-mixer/actions | ||
[ts-versions]: https://badgen.net/badge/icon/3.8,3.9,4.0,4.1,4.2?icon=typescript&label&list=| | ||
[ts-versions]: https://badgen.net/badge/icon/4.2,4.3?icon=typescript&label&list=| | ||
[node-versions]: https://badgen.net/badge/node/10%2C12%2C14/blue/?list=| | ||
@@ -29,16 +29,15 @@ [![npm version][version-badge]][version-link] | ||
* supports protected/private properties (the popular function-that-returns-a-class solution does not) | ||
* mixes abstract classes (with caveats [[1](#caveats)]) | ||
* mixes generic classes (with caveats [[2](#caveats)]) | ||
* supports class, method, and property decorators (with caveats [[3, 6](#caveats)]) | ||
* mostly supports the complexity presented by constructor functions (with caveats [[4](#caveats)]) | ||
* comes with an `instanceof`-like replacement (with caveats [[5, 6](#caveats)]) | ||
* mixes abstract classes (requires TypeScript >= 4.2) | ||
* mixes generic classes (with caveats [[1](#caveats)]) | ||
* supports class, method, and property decorators (with caveats [[2, 5](#caveats)]) | ||
* mostly supports the complexity presented by constructor functions (with caveats [[3](#caveats)]) | ||
* comes with an `instanceof`-like replacement (with caveats [[4, 5](#caveats)]) | ||
* [multiple mixing strategies](#settings) (ES6 proxies vs hard copy) | ||
### Caveats | ||
1. Mixing abstract classes requires a bit of a hack that may break in future versions of TypeScript. See [mixing abstract classes](#mixing-abstract-classes) below. | ||
2. Mixing generic classes requires a more cumbersome notation, but it's still possible. See [mixing generic classes](#mixing-generic-classes) below. | ||
3. Using decorators in mixed classes also requires a more cumbersome notation. See [mixing with decorators](#mixing-with-decorators) below. | ||
4. ES6 made it impossible to use `.apply(...)` on class constructors (or any means of calling them without `new`), which makes it impossible for `ts-mixer` to pass the proper `this` to your constructors. This may or may not be an issue for your code, but there are options to work around it. See [dealing with constructors](#dealing-with-constructors) below. | ||
5. `ts-mixer` does not support `instanceof` for mixins, but it does offer a replacement. See the [hasMixin function](#hasmixin) for more details. | ||
6. Certain features (specifically, `@decorator` and `hasMixin`) make use of ES6 `Map`s, which means you must either use ES6+ or polyfill `Map` to use them. If you don't need these features, you should be fine without. | ||
1. Mixing generic classes requires a more cumbersome notation, but it's still possible. See [mixing generic classes](#mixing-generic-classes) below. | ||
2. Using decorators in mixed classes also requires a more cumbersome notation. See [mixing with decorators](#mixing-with-decorators) below. | ||
3. ES6 made it impossible to use `.apply(...)` on class constructors (or any means of calling them without `new`), which makes it impossible for `ts-mixer` to pass the proper `this` to your constructors. This may or may not be an issue for your code, but there are options to work around it. See [dealing with constructors](#dealing-with-constructors) below. | ||
4. `ts-mixer` does not support `instanceof` for mixins, but it does offer a replacement. See the [hasMixin function](#hasmixin) for more details. | ||
5. Certain features (specifically, `@decorator` and `hasMixin`) make use of ES6 `Map`s, which means you must either use ES6+ or polyfill `Map` to use them. If you don't need these features, you should be fine without. | ||
@@ -85,31 +84,2 @@ ## Quick Start | ||
## Special Cases | ||
### Mixing Abstract Classes | ||
Abstract classes, by definition, cannot be constructed, which means they cannot take on the type, `new(...args) => any`, and by extension, are incompatible with `ts-mixer`. BUT, you can "trick" TypeScript into giving you all the benefits of an abstract class without making it technically abstract. The trick is just some strategic `// @ts-ignore`'s: | ||
```typescript | ||
import { Mixin } from 'ts-mixer'; | ||
// note that Foo is not marked as an abstract class | ||
class Foo { | ||
// @ts-ignore: "Abstract methods can only appear within an abstract class" | ||
public abstract makeFoo(): string; | ||
} | ||
class Bar { | ||
public makeBar() { | ||
return 'bar'; | ||
} | ||
} | ||
class FooBar extends Mixin(Foo, Bar) { | ||
// we still get all the benefits of abstract classes here, because TypeScript | ||
// will still complain if this method isn't implemented | ||
public makeFoo() { | ||
return 'foo'; | ||
} | ||
} | ||
``` | ||
Do note that while this does work quite well, it is a bit of a hack and I can't promise that it will continue to work in future TypeScript versions. | ||
### Mixing Generic Classes | ||
@@ -116,0 +86,0 @@ Frustratingly, it is _impossible_ for generic parameters to be referenced in base class expressions. No matter what, you will eventually run into `Base class expressions cannot reference class type parameters.` |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
0
73107
918
1
273