Releases: jc-verse/ts-klass
Releases · jc-verse/ts-klass
v0.5.0
Features:
- Accessors. Previously we used
Object.entries
to map the klass body, which means accessors are flattened to data properties. We now useObject.getOwnPropertyDescriptors
, which helps to preserve the accessors' nature. Non-enumerable properties are still ignored as before. klass.configure
. We added a new top-level API that allows you to configure certain behaviors of klasses. Currently, we offer two options:constructWithNеw
: a linter-like feature that requires every klass construction to go throughnеw
instead of being called directly.UNSAFE_disableNoThisBeforeSuperCheck
: as the name implies, do not use this unless you know what you are doing. This allows you to accessthis
before callingsuper.constructor
in the klass constructor. This means you can access the uninitialized klass instance. The accessors/methods will still be present, though, because they are statically defined on the prototype.
v0.4.0
Features:
- In the last release (v0.3.0), we added the
extends
API. At that time, it was neither documented nor actually functional. In this release, it is fully functional. - You can use
extends
to bind prototypes, and even callsuper.constructor
,super.method
, etc. - Accessing
this
is disallowed beforesuper
. We even offer better error messages than v8 (because we have to use a proxy anyways). However, we may not be able to catch all usage tothis
, particularly those that don't trigger proxy traps.
Bug fixes:
- We fixed an ECMAScript conformance failure where
const K = klass({ field: 1 })
would havefield
defined onK.prototype
instead of every instance ofK
.field
should be seen as a class field.- Our heuristic for "class field vs. class method" is currently
typeof value === "function"
. This is not ideal becauseconst K = klass({ field: () => {} })
should still be a class field. If you have a better algorithm to differentiate methods from function properties (testing for construtibility won't work, because arrow functions aren't constructible either), contributions welcome.
- Our heuristic for "class field vs. class method" is currently
We added a lot of ES conformance tests to ensure that we are maximally compatible with ES semantics, especially in terms of prototype assignment.
v0.3.0
Features:
- Better
toString
behavior: returns[object <KlassName>]
instead of[object Object]
(ECMAScript conformance) Klass.length
returns the length of the constructor function (ECMAScript conformance)- New klass branded check method:
Klass instanceof klass
The internal code is also structured in a much better way now.