Skip to content

Commit d3c513b

Browse files
committed
fix: ignore non-enumerable properties
1 parent d681abd commit d3c513b

File tree

3 files changed

+9
-1
lines changed

3 files changed

+9
-1
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "ts-klass",
3-
"version": "0.5.0",
3+
"version": "0.5.1",
44
"description": "Type-strong klasses",
55
"main": "src/index.js",
66
"types": "src/index.d.ts",

src/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ function splitBody(body) {
1515
instanceMethods = [];
1616
Object.entries(Object.getOwnPropertyDescriptors(body)).forEach(
1717
([key, value]) => {
18+
if (!value.enumerable) return;
1819
if (key.startsWith("static "))
1920
staticFields.push([key.replace(/^static /, ""), value]);
2021
// TODO: `{ foo() {} }` and `{ foo: function () {} }` should be

test/index.test.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,13 @@ describe("klass constructor", () => {
7575
expect(cat.name).toBe("Fiona");
7676
});
7777

78+
it("ignores non-enumerable properties", () => {
79+
const body = {};
80+
Object.defineProperty(body, "hidden", { value: 1 });
81+
const Animal = klass(body);
82+
expect(Animal().hidden).toBe(undefined);
83+
});
84+
7885
describe("accepts getters & setters", () => {
7986
test("klass", () => {
8087
const Animal = klass({

0 commit comments

Comments
 (0)