Skip to content

Commit 2413c0f

Browse files
committed
fix logic in marks to adhere to types
1 parent 058516b commit 2413c0f

1 file changed

Lines changed: 9 additions & 5 deletions

File tree

src/mark.ts

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
type PropertyType = 'field' | 'getter' | 'setter' | 'method'
2-
type PropertyDecorator = (proto: object, key: PropertyKey) => void
2+
interface PropertyDecorator {
3+
(proto: object, key: PropertyKey, descriptor?: PropertyDescriptor): void
4+
readonly static: unique symbol
5+
}
36
type GetMarks = (instance: object) => Set<PropertyKey>
47
export function createMark(validate: (key: PropertyKey, type: PropertyType) => void): [PropertyDecorator, GetMarks] {
58
const marks = new WeakMap<object, Set<PropertyKey>>()
6-
const sym = Symbol()
79
function get(proto: object): Set<PropertyKey> {
810
if (!marks.has(proto)) {
911
const parent = Object.getPrototypeOf(proto)
@@ -22,13 +24,15 @@ export function createMark(validate: (key: PropertyKey, type: PropertyType) => v
2224
validate(key, type)
2325
get(proto).add(key)
2426
}
25-
marker.static = sym
27+
marker.static = Symbol()
2628

2729
return [
28-
marker,
30+
marker as PropertyDecorator,
2931
(instance: object): Set<PropertyKey> => {
3032
const proto = Object.getPrototypeOf(instance)
31-
for (const key of proto.constructor[sym] || []) marker(proto, key, Object.getOwnPropertyDescriptor(proto, key))
33+
for (const key of proto.constructor[marker.static] || []) {
34+
marker(proto, key, Object.getOwnPropertyDescriptor(proto, key))
35+
}
3236
return new Set(get(proto))
3337
}
3438
]

0 commit comments

Comments
 (0)