aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSam Wilkins <samwilkins333@gmail.com>2019-10-15 18:35:56 -0400
committerSam Wilkins <samwilkins333@gmail.com>2019-10-15 18:35:56 -0400
commit4e65c84c768da1eabeca552df54ea1ed78812f8e (patch)
tree379b7b9a30fa8b061d6ba87dbdd065a1e84fee9c
parent33811c112c7e479813908ba10f72813954a3e289 (diff)
fixed fatal mobx extension-related error, still can use extensions
-rw-r--r--src/extensions/ArrayExtensions.ts34
1 files changed, 29 insertions, 5 deletions
diff --git a/src/extensions/ArrayExtensions.ts b/src/extensions/ArrayExtensions.ts
index 422a10dbc..8e125766d 100644
--- a/src/extensions/ArrayExtensions.ts
+++ b/src/extensions/ArrayExtensions.ts
@@ -1,13 +1,37 @@
-function Assign() {
+export default class ArrayExtension {
+ private readonly property: string;
+ private readonly body: <T>(this: Array<T>) => any;
+
+ constructor(property: string, body: <T>(this: Array<T>) => any) {
+ this.property = property;
+ this.body = body;
+ }
+
+ assign() {
+ Object.defineProperty(Array.prototype, this.property, {
+ value: this.body,
+ enumerable: false
+ });
+ }
- Array.prototype.lastElement = function <T>() {
+}
+
+/**
+ * IMPORTANT: Any extension you add here *must* have a corresponding type definition
+ * in the Array<T> interface in ./General/ExtensionsTypings.ts. Otherwise,
+ * Typescript will not recognize your new function.
+ */
+const extensions = [
+ new ArrayExtension("lastElement", function () {
if (!this.length) {
return undefined;
}
- const last: T = this[this.length - 1];
- return last;
- };
+ return this[this.length - 1];
+ })
+];
+function Assign() {
+ extensions.forEach(extension => extension.assign());
}
export { Assign }; \ No newline at end of file