Skip to content

Commit 8fba18f

Browse files
committed
chore: InMemoryEntityInSetMixin types
1 parent 2cf3ebc commit 8fba18f

File tree

3 files changed

+12
-9
lines changed

3 files changed

+12
-9
lines changed

dist/js/entity/set/mixins.d.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1+
import { SystemInSetSchema } from "@mat3ra/esse/dist/js/types";
12
import { InMemoryEntityConstructor } from "../in_memory";
3+
export type SystemInSet = Required<SystemInSetSchema>;
4+
export type InSet = SystemInSet["inSet"][0];
25
export declare function InMemoryEntityInSetMixin<T extends InMemoryEntityConstructor>(superclass: T): {
36
new (...args: any[]): {
47
inSet: {

dist/js/entity/set/mixins.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,7 @@ exports.InMemoryEntityInSetMixin = InMemoryEntityInSetMixin;
2323
function InMemoryEntitySetMixin(superclass) {
2424
return class InMemoryEntitySetMixin extends superclass {
2525
containsEntity(entity) {
26-
var _a;
27-
return (_a = entity === null || entity === void 0 ? void 0 : entity.inSet) === null || _a === void 0 ? void 0 : _a.some((ref) => ref._id === this.id);
26+
return entity === null || entity === void 0 ? void 0 : entity.inSet.some((ref) => ref._id === this.id);
2827
}
2928
};
3029
}

src/js/entity/set/mixins.ts

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,16 @@ import { SystemInSetSchema } from "@mat3ra/esse/dist/js/types";
22

33
import { InMemoryEntityConstructor } from "../in_memory";
44

5-
type SystemInSet = Required<SystemInSetSchema>;
5+
export type SystemInSet = Required<SystemInSetSchema>;
6+
export type InSet = SystemInSet["inSet"][0];
67

78
export function InMemoryEntityInSetMixin<T extends InMemoryEntityConstructor>(superclass: T) {
89
return class InMemoryEntityInSetMixin extends superclass implements SystemInSet {
910
get inSet() {
10-
return this.prop("inSet", []);
11+
return this.prop<InSet[]>("inSet", []);
1112
}
1213

13-
set inSet(inSet: SystemInSet["inSet"]) {
14+
set inSet(inSet: InSet[]) {
1415
this.setProp("inSet", inSet);
1516
}
1617

@@ -26,12 +27,12 @@ export function InMemoryEntityInSetMixin<T extends InMemoryEntityConstructor>(su
2627
};
2728
}
2829

30+
type BaseEntityInSet = InstanceType<ReturnType<typeof InMemoryEntityInSetMixin>>;
31+
2932
export function InMemoryEntitySetMixin<T extends InMemoryEntityConstructor>(superclass: T) {
3033
return class InMemoryEntitySetMixin extends superclass {
31-
containsEntity<T extends InstanceType<ReturnType<typeof InMemoryEntityInSetMixin>>>(
32-
entity?: T,
33-
) {
34-
return entity?.inSet?.some((ref) => ref._id === this.id);
34+
containsEntity<T extends BaseEntityInSet>(entity?: T) {
35+
return entity?.inSet.some((ref) => ref._id === this.id);
3536
}
3637
};
3738
}

0 commit comments

Comments
 (0)