typecomposer 0.1.42 → 0.1.44

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,31 +1,70 @@
1
1
  import { Ref } from ".";
2
2
  import { RefContainer } from "./RefContainer";
3
+ /**
4
+ * Creates a new reactive list wrapper around a standard array.
5
+ *
6
+ * @param items - The initial array of items.
7
+ * @returns A new instance of RefList.
8
+ */
3
9
  export function refList(items) {
4
10
  return new RefList(items);
5
11
  }
12
+ // Enables `instanceof refList` to work correctly
6
13
  Object.defineProperty(refList, Symbol.hasInstance, {
7
14
  value: function (instance) {
8
15
  return !!instance && instance instanceof RefList;
9
16
  },
10
17
  });
18
+ /**
19
+ * A reactive wrapper for arrays that notifies subscribers on mutation.
20
+ * Inherits from Array and intercepts mutations like push, pop, splice, etc.
21
+ */
11
22
  export class RefList extends Array {
23
+ /**
24
+ * Internal container that manages the reactive value and its subscribers.
25
+ */
12
26
  container;
27
+ /**
28
+ * A unique key identifying this list reference (optional).
29
+ */
13
30
  refKey;
31
+ /**
32
+ * Constructs a new RefList instance with the given items.
33
+ *
34
+ * @param items - The initial items for the list.
35
+ * @param refKey - Optional key used for registration in a central Ref registry.
36
+ */
14
37
  constructor(items, refKey) {
15
38
  super(...items);
16
39
  this.refKey = refKey;
17
40
  this.container = new RefContainer(this);
18
41
  refKey && Ref.set(refKey, this);
19
42
  }
43
+ /**
44
+ * Emits a change event to all subscribers for a specific mutation.
45
+ *
46
+ * @param propertyName - The type of mutation (e.g., "push", "splice", "value").
47
+ * @param value - The new list value.
48
+ */
20
49
  emit(propertyName, value) {
21
50
  this.container.emitAll(propertyName, value);
22
51
  }
52
+ /**
53
+ * Subscribes to list changes and immediately emits the current value.
54
+ */
23
55
  subscribe(target, propertyName, onUnsubscribe) {
24
56
  return this.container.emit(this.container.subscribe(target, propertyName, onUnsubscribe), this);
25
57
  }
58
+ /**
59
+ * Subscribes to future changes without emitting the current value.
60
+ */
61
+ listen(target, onUnsubscribe) {
62
+ return this.container.subscribe(target, onUnsubscribe) !== undefined;
63
+ }
26
64
  unsubscribe(targe, propertyName = "") {
27
65
  return this.container.unsubscribe(targe, propertyName);
28
66
  }
67
+ /** Reactive mutation overrides **/
29
68
  push(...items) {
30
69
  const n = super.push(...items);
31
70
  this.container.emitAll("push", this);
@@ -71,19 +110,31 @@ export class RefList extends Array {
71
110
  this.container.emitAll("copyWithin", this);
72
111
  return this;
73
112
  }
113
+ /**
114
+ * Changes the length of the array and emits a change.
115
+ */
74
116
  set length(value) {
75
117
  super.length = value;
76
118
  this.container.emitAll("length", this);
77
119
  }
120
+ /**
121
+ * Clears all elements in the list.
122
+ */
78
123
  clear() {
79
124
  super.length = 0;
80
125
  this.container.emitAll("clear", this);
81
126
  }
127
+ /**
128
+ * Inserts items at a specific index.
129
+ */
82
130
  insert(index, ...items) {
83
131
  super.splice(index, 0, ...items);
84
132
  this.container.emitAll("insert", this);
85
133
  return this.length;
86
134
  }
135
+ /**
136
+ * Removes a specific item from the list.
137
+ */
87
138
  removeItem(value) {
88
139
  const index = super.indexOf(value);
89
140
  if (index === -1)
@@ -92,11 +143,17 @@ export class RefList extends Array {
92
143
  this.container.emitAll("removeValue", this);
93
144
  return value;
94
145
  }
146
+ /**
147
+ * Removes elements starting from an index.
148
+ */
95
149
  remove(index, count = 1) {
96
150
  super.splice(index, count);
97
151
  this.container.emitAll("remove", this);
98
152
  return this.length;
99
153
  }
154
+ /**
155
+ * Returns a shallow copy of the current list.
156
+ */
100
157
  valueOf() {
101
158
  return Array.from(this);
102
159
  }
@@ -104,16 +161,10 @@ export class RefList extends Array {
104
161
  return super.length;
105
162
  }
106
163
  /**
107
- * Synchronizes the children of an HTML element (`element`) with the provided list of `HTMLElement`s (`list`).
108
- * Ensures that the `element` contains the same elements as in the `list`, in the same order.
164
+ * Synchronizes the children of an HTML element with a list of HTMLElements.
109
165
  *
110
- * Behavior:
111
- * 1. Removes children from `element` that are not in `list`.
112
- * 2. Appends elements from `list` to `element` that are not already present.
113
- * 3. Reorders children of `element` to match the order in `list`.
114
- *
115
- * @param list - An array of `HTMLElement`s that should be reflected as the children of `element`.
116
- * @param element - The parent `HTMLElement` whose children will be synchronized with `list`.
166
+ * @param list - The list of elements to reflect in the container.
167
+ * @param element - The container element whose children will be updated.
117
168
  */
118
169
  static syncComponentWithList(list, element) {
119
170
  const currentChildren = Array.from(element.children);
@@ -134,17 +185,31 @@ export class RefList extends Array {
134
185
  }
135
186
  });
136
187
  }
188
+ /**
189
+ * Identifies this object as a custom reactive list in `Object.prototype.toString`.
190
+ */
137
191
  get [Symbol.toStringTag]() {
138
192
  return "refList";
139
193
  }
194
+ /**
195
+ * Ensures Array is returned when using methods like `slice()` or `map()`.
196
+ */
140
197
  static get [Symbol.species]() {
141
198
  return Array;
142
199
  }
143
- // @ts-ignore
200
+ /**
201
+ * Gets the current value of the reactive list.
202
+ * Returns a shallow copy of the internal array to prevent direct mutation.
203
+ */
144
204
  get value() {
145
205
  return this.container.value.valueOf();
146
206
  }
147
- // @ts-ignore
207
+ /**
208
+ * Replaces the entire contents of the list with a new array of items.
209
+ * If the same array reference is passed, no update or notification occurs.
210
+ *
211
+ * @param value - The new array of items to assign.
212
+ */
148
213
  set value(value) {
149
214
  // @ts-ignore
150
215
  if (this === value)
@@ -152,7 +217,10 @@ export class RefList extends Array {
152
217
  super.splice(0, this.length, ...value);
153
218
  this.emit("value", value);
154
219
  }
155
- // @ts-ignore
220
+ /**
221
+ * Serializes the current list value for JSON output.
222
+ * This ensures only the raw array contents are emitted.
223
+ */
156
224
  toJSON() {
157
225
  return this.value;
158
226
  }
@@ -1 +1 @@
1
- {"version":3,"file":"RefList.js","sourceRoot":"","sources":["../../../src/core/ref/RefList.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAO,MAAM,GAAG,CAAC;AAC7B,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAE9C,MAAM,UAAU,OAAO,CAAI,KAAU;IACnC,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AAE,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAC,IAAI,IAAI,CAAC,CAAC;YAC5D,CAAC;QACH,CAAC,CAAC,CAAC;IACL,CAAC;IAED;;OAEG;IACH,IAAI,CAAC,MAAM,CAAC,WAAW,CAAC;QACtB,OAAO,SAAS,CAAC;IACnB,CAAC;IAED;;OAEG;IACH,MAAM,KAAK,CAAC,MAAM,CAAC,OAAO,CAAC;QACzB,OAAO,KAAK,CAAC;IACf,CAAC;IAGD;;;MAGE;IACF,IAAI,KAAK;QACP,OAAO,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,OAAO,EAAE,CAAC;IACxC,CAAC;IAED;;;;;OAKG;IACH,IAAI,KAAK,CAAC,KAAU;QAClB,aAAa;QACb,IAAI,IAAI,KAAK,KAAK;YAAE,OAAO;QAC3B,KAAK,CAAC,MAAM,CAAC,CAAC,EAAE,IAAI,CAAC,MAAM,EAAE,GAAG,KAAK,CAAC,CAAC;QACvC,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC;IAC5B,CAAC;IAED;;;OAGG;IACH,MAAM;QACJ,OAAO,IAAI,CAAC,KAAK,CAAC;IACpB,CAAC;CAEF"}
@@ -1,25 +1,104 @@
1
1
  import { ref } from ".";
2
2
  import { RefContainer } from "./RefContainer";
3
+ /**
4
+ * Creates a new reactive map from the given entries.
5
+ *
6
+ * @param entries - Optional initial key-value pairs.
7
+ * @returns A reactive RefMap instance.
8
+ */
3
9
  export declare function refMap<K, V>(entries?: readonly (readonly [K, V])[] | null): RefMap<K, V>;
10
+ /**
11
+ * A type representing either a native Map or a reactive RefMap.
12
+ */
4
13
  export type refMap<K, V> = Map<K, V> | RefMap<K, V>;
14
+ /**
15
+ * A reactive wrapper around the native Map object.
16
+ * Supports automatic reactivity and subscription to changes.
17
+ */
5
18
  export declare class RefMap<K, V> extends Map<K, V> implements ref<Map<K, V>> {
19
+ /**
20
+ * Internal container managing subscribers and value propagation.
21
+ */
6
22
  readonly container: RefContainer;
23
+ /**
24
+ * Optional key to register the reference globally.
25
+ */
7
26
  readonly refKey: string;
27
+ /**
28
+ * Constructs a new reactive map instance.
29
+ *
30
+ * @param entries - Optional initial entries to populate the map.
31
+ * @param refKey - Optional registration key for the Ref registry.
32
+ */
8
33
  constructor(entries?: readonly (readonly [K, V])[] | null, refKey?: string);
34
+ /**
35
+ * Emits a change event to all subscribers for a given mutation type.
36
+ *
37
+ * @param propertyName - The kind of mutation (e.g., "set", "clear").
38
+ * @param value - The current state of the map.
39
+ */
9
40
  private emit;
41
+ /** Reactive subscription methods **/
10
42
  subscribe(target: (arg: Map<K, V>) => void): boolean;
11
43
  subscribe(target: (arg: Map<K, V>) => void, onUnsubscribe: Function): boolean;
12
44
  subscribe(target: object, propertyName: string | symbol): boolean;
13
45
  subscribe(target: object, propertyName: string | symbol, onUnsubscribe: Function): boolean;
14
46
  subscribe(target: object | ((arg: Map<K, V>) => void), propertyName: string | symbol | Function, onUnsubscribe?: Function): boolean;
47
+ /**
48
+ * Subscribes to future changes without emitting the current value.
49
+ *
50
+ * @param target - Function to call on change.
51
+ * @param onUnsubscribe - Optional callback to invoke on unsubscription.
52
+ */
53
+ listen(target: (arg: Map<K, V>) => void, onUnsubscribe?: Function): boolean;
54
+ /**
55
+ * Unsubscribes a function or object-property pair from receiving updates.
56
+ */
15
57
  unsubscribe(target: (arg: Map<K, V>) => void): boolean;
16
58
  unsubscribe(targe: object, propertyName: string | symbol): boolean;
59
+ /** Reactive mutation overrides **/
60
+ /**
61
+ * Sets a value for a given key and notifies subscribers.
62
+ *
63
+ * @param key - The key to insert or update.
64
+ * @param value - The value to associate with the key.
65
+ * @returns The map itself.
66
+ */
17
67
  set(key: K, value: V): this;
68
+ /**
69
+ * Deletes a key-value pair and notifies subscribers.
70
+ *
71
+ * @param key - The key to delete.
72
+ * @returns True if the key existed and was removed.
73
+ */
18
74
  delete(key: K): boolean;
75
+ /**
76
+ * Clears all entries from the map and notifies subscribers.
77
+ */
19
78
  clear(): void;
79
+ /**
80
+ * Returns a shallow copy of the current map state.
81
+ */
20
82
  valueOf(): Map<K, V>;
83
+ /**
84
+ * Ensures native `Map` is returned when using `Map` methods that create new instances.
85
+ */
21
86
  static get [Symbol.species](): MapConstructor;
87
+ /**
88
+ * Gets the current value of the reactive map.
89
+ * Returns a shallow copy to prevent unintended mutation.
90
+ */
22
91
  get value(): Map<K, V>;
92
+ /**
93
+ * Sets the entire contents of the map to match the given Map instance.
94
+ * If the same reference is passed, no update is triggered.
95
+ *
96
+ * @param value - A new Map to replace the current contents.
97
+ */
23
98
  set value(value: Map<K, V>);
99
+ /**
100
+ * Serializes the map to a plain JavaScript object for JSON output.
101
+ * Note: keys are converted to string.
102
+ */
24
103
  toJSON(): any;
25
104
  }
@@ -1,56 +1,129 @@
1
1
  import { Ref } from ".";
2
2
  import { RefContainer } from "./RefContainer";
3
+ /**
4
+ * Creates a new reactive map from the given entries.
5
+ *
6
+ * @param entries - Optional initial key-value pairs.
7
+ * @returns A reactive RefMap instance.
8
+ */
3
9
  export function refMap(entries) {
4
10
  return new RefMap(entries);
5
11
  }
12
+ // Enables `instanceof refMap` to work correctly
6
13
  Object.defineProperty(refMap, Symbol.hasInstance, {
7
14
  value: function (instance) {
8
15
  return !!instance && instance instanceof RefMap;
9
16
  },
10
17
  });
11
- // @ts-ignore
18
+ /**
19
+ * A reactive wrapper around the native Map object.
20
+ * Supports automatic reactivity and subscription to changes.
21
+ */
12
22
  export class RefMap extends Map {
23
+ /**
24
+ * Internal container managing subscribers and value propagation.
25
+ */
13
26
  container = new RefContainer(this);
27
+ /**
28
+ * Optional key to register the reference globally.
29
+ */
14
30
  refKey;
31
+ /**
32
+ * Constructs a new reactive map instance.
33
+ *
34
+ * @param entries - Optional initial entries to populate the map.
35
+ * @param refKey - Optional registration key for the Ref registry.
36
+ */
15
37
  constructor(entries, refKey) {
16
38
  super();
17
39
  this.refKey = refKey;
18
40
  refKey && Ref.set(refKey, this);
19
41
  this.value = new Map(entries);
20
42
  }
43
+ /**
44
+ * Emits a change event to all subscribers for a given mutation type.
45
+ *
46
+ * @param propertyName - The kind of mutation (e.g., "set", "clear").
47
+ * @param value - The current state of the map.
48
+ */
21
49
  // @ts-ignore
22
50
  emit(propertyName, value) {
23
51
  this.container.emitAll(propertyName, value);
24
52
  }
53
+ /**
54
+ * Subscribes to changes and immediately emits the current map value.
55
+ */
25
56
  subscribe(target, propertyName, onUnsubscribe) {
26
57
  return this.container.emit(this.container.subscribe(target, propertyName, onUnsubscribe), this);
27
58
  }
59
+ /**
60
+ * Subscribes to future changes without emitting the current value.
61
+ *
62
+ * @param target - Function to call on change.
63
+ * @param onUnsubscribe - Optional callback to invoke on unsubscription.
64
+ */
65
+ listen(target, onUnsubscribe) {
66
+ return this.container.subscribe(target, onUnsubscribe) !== undefined;
67
+ }
28
68
  unsubscribe(targe, propertyName = "") {
29
69
  return this.container.unsubscribe(targe, propertyName);
30
70
  }
71
+ /** Reactive mutation overrides **/
72
+ /**
73
+ * Sets a value for a given key and notifies subscribers.
74
+ *
75
+ * @param key - The key to insert or update.
76
+ * @param value - The value to associate with the key.
77
+ * @returns The map itself.
78
+ */
31
79
  set(key, value) {
32
80
  const result = super.set(key, value);
33
81
  this.container.emitAll("set", this);
34
82
  return result;
35
83
  }
84
+ /**
85
+ * Deletes a key-value pair and notifies subscribers.
86
+ *
87
+ * @param key - The key to delete.
88
+ * @returns True if the key existed and was removed.
89
+ */
36
90
  delete(key) {
37
91
  const result = super.delete(key);
38
92
  this.container.emitAll("delete", this);
39
93
  return result;
40
94
  }
95
+ /**
96
+ * Clears all entries from the map and notifies subscribers.
97
+ */
41
98
  clear() {
42
99
  super.clear();
43
100
  this.container.emitAll("clear", this);
44
101
  }
102
+ /**
103
+ * Returns a shallow copy of the current map state.
104
+ */
45
105
  valueOf() {
46
106
  return new Map(Array.from(this));
47
107
  }
108
+ /**
109
+ * Ensures native `Map` is returned when using `Map` methods that create new instances.
110
+ */
48
111
  static get [Symbol.species]() {
49
112
  return Map;
50
113
  }
114
+ /**
115
+ * Gets the current value of the reactive map.
116
+ * Returns a shallow copy to prevent unintended mutation.
117
+ */
51
118
  get value() {
52
119
  return this.container.value.valueOf();
53
120
  }
121
+ /**
122
+ * Sets the entire contents of the map to match the given Map instance.
123
+ * If the same reference is passed, no update is triggered.
124
+ *
125
+ * @param value - A new Map to replace the current contents.
126
+ */
54
127
  set value(value) {
55
128
  if (this === value)
56
129
  return;
@@ -60,6 +133,10 @@ export class RefMap extends Map {
60
133
  }
61
134
  this.emit("value", value);
62
135
  }
136
+ /**
137
+ * Serializes the map to a plain JavaScript object for JSON output.
138
+ * Note: keys are converted to string.
139
+ */
63
140
  toJSON() {
64
141
  const obj = {};
65
142
  for (const [k, v] of this.value) {
@@ -1 +1 @@
1
- {"version":3,"file":"RefMap.js","sourceRoot":"","sources":["../../../src/core/ref/RefMap.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAO,MAAM,GAAG,CAAC;AAC7B,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAE9C,MAAM,UAAU,MAAM,CAAO,OAA6C;IACxE,OAAO,IAAI,MAAM,CAAO,OAAO,CAAC,CAAC;AACnC,CAAC;AAED,MAAM,CAAC,cAAc,CAAC,MAAM,EAAE,MAAM,CAAC,WAAW,EAAE;IAChD,KAAK,EAAE,UAAU,QAAa;QAC5B,OAAO,CAAC,CAAC,QAAQ,IAAI,QAAQ,YAAY,MAAM,CAAC;IAClD,CAAC;CACF,CAAC,CAAC;AAGH,aAAa;AACb,MAAM,OAAO,MAAa,SAAQ,GAAS;IAChC,SAAS,GAAiB,IAAI,YAAY,CAAC,IAAI,CAAC,CAAC;IACjD,MAAM,CAAS;IAExB,YAAY,OAA6C,EAAE,MAAe;QACxE,KAAK,EAAE,CAAC;QACR,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,MAAM,IAAI,GAAG,CAAC,GAAG,CAAC,MAAM,EAAE,IAAW,CAAC,CA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AAC,CAAC,GAAG,CAAC,CAAC;QACb,CAAC;QACD,OAAO,GAAG,CAAC;IACb,CAAC;CACF"}
@@ -1,30 +1,123 @@
1
1
  import { ref } from ".";
2
2
  import { RefContainer } from "./RefContainer";
3
+ /**
4
+ * Creates a reactive wrapper for a numeric value.
5
+ *
6
+ * @param value - The initial number value.
7
+ * @returns A new instance of RefNumber.
8
+ */
3
9
  export declare function refNumber(value: number): RefNumber;
10
+ /**
11
+ * A union type representing either a primitive number or a reactive RefNumber.
12
+ */
4
13
  export type refNumber = number | RefNumber;
14
+ /**
15
+ * A reactive wrapper for numbers that behaves like a Number object.
16
+ * Allows subscriptions to value changes and integrates with primitive operations.
17
+ */
5
18
  export declare class RefNumber implements Number, ref<number> {
19
+ /**
20
+ * The container holding the internal value and managing subscriptions.
21
+ */
6
22
  readonly container: RefContainer;
23
+ /**
24
+ * A unique identifier used for external reference tracking (optional).
25
+ */
7
26
  readonly refKey: string;
27
+ /**
28
+ * Constructs a new reactive number wrapper.
29
+ *
30
+ * @param value - The initial number value.
31
+ * @param refKey - Optional key used to register in a shared Ref registry.
32
+ */
8
33
  constructor(value: number, refKey?: string);
9
- toFixed(fractionDigits?: number): string;
10
- toExponential(fractionDigits?: number): string;
11
- toPrecision(precision?: number): string;
12
- valueOf(): number;
13
- toLocaleString(locales?: string, options?: Intl.NumberFormatOptions): string;
34
+ /**
35
+ * Emits a change notification if the value has changed.
36
+ *
37
+ * @param propertyName - The name of the property being updated (usually "value").
38
+ * @param value - The new number value to assign.
39
+ */
14
40
  private emit;
41
+ /** Reactive subscription methods **/
15
42
  subscribe(target: (arg: number) => void): boolean;
16
43
  subscribe(target: (arg: number) => void, onUnsubscribe: Function): boolean;
17
44
  subscribe(target: object, propertyName: string | symbol): boolean;
18
45
  subscribe(target: object, propertyName: string | symbol, onUnsubscribe: Function): boolean;
19
46
  subscribe(target: object | ((arg: number) => void), propertyName: string | symbol | Function, onUnsubscribe?: Function): boolean;
47
+ /**
48
+ * Subscribes to future value changes without emitting the current number.
49
+ *
50
+ * @param target - A function to be called on future updates.
51
+ * @param onUnsubscribe - Optional callback to be called upon unsubscription.
52
+ * @returns true if successfully subscribed.
53
+ */
54
+ listen(target: (arg: number) => void, onUnsubscribe?: Function): boolean;
55
+ /**
56
+ * Unsubscribes a function or object property from receiving value updates.
57
+ */
20
58
  unsubscribe(target: (arg: number) => void): boolean;
21
59
  unsubscribe(targe: object, propertyName: string | symbol): boolean;
22
- [Symbol.toPrimitive](hint: string): number;
23
- static get [Symbol.species](): NumberConstructor;
60
+ /** Value access and primitives **/
61
+ /**
62
+ * Gets the current number value.
63
+ */
24
64
  get value(): number;
65
+ /**
66
+ * Sets a new number value and notifies subscribers if it changed.
67
+ *
68
+ * @param value - The new number to set.
69
+ */
25
70
  set value(value: number);
71
+ /**
72
+ * Returns the primitive number value.
73
+ */
74
+ valueOf(): number;
75
+ /**
76
+ * Converts the value to a string using an optional radix.
77
+ *
78
+ * @param radix - An integer between 2 and 36 specifying the base.
79
+ */
80
+ toString(radix?: number): string;
81
+ /**
82
+ * Converts the value to fixed-point notation.
83
+ *
84
+ * @param fractionDigits - Number of digits after the decimal point.
85
+ */
86
+ toFixed(fractionDigits?: number): string;
87
+ /**
88
+ * Converts the value to exponential notation.
89
+ *
90
+ * @param fractionDigits - Number of digits after the decimal point.
91
+ */
92
+ toExponential(fractionDigits?: number): string;
93
+ /**
94
+ * Formats the number to a specified precision.
95
+ *
96
+ * @param precision - Total number of significant digits.
97
+ */
98
+ toPrecision(precision?: number): string;
99
+ /**
100
+ * Formats the number according to locale-specific rules.
101
+ *
102
+ * @param locales - A locale string or array of locale strings.
103
+ * @param options - Formatting options.
104
+ */
105
+ toLocaleString(locales?: string, options?: Intl.NumberFormatOptions): string;
106
+ /**
107
+ * Supports automatic type coercion to a number in JS expressions.
108
+ *
109
+ * @param hint - Either "number", "string", or "default".
110
+ */
111
+ [Symbol.toPrimitive](hint: string): number;
112
+ /**
113
+ * Identifies this class as a subtype of `Number`.
114
+ */
115
+ static get [Symbol.species](): NumberConstructor;
116
+ /**
117
+ * Serializes the current value for JSON output.
118
+ * If this instance is the root ref, emits the raw value, otherwise wraps it.
119
+ */
26
120
  toJSON(): number | {
27
121
  value: number;
28
122
  };
29
- toString(radix?: number): string;
30
123
  }