serialijse icon indicating copy to clipboard operation
serialijse copied to clipboard

Class property functions unable to be serialized, though methods can

Open homomorphist opened this issue 3 years ago • 0 comments

Hello! The title describes the issue I am facing. I don't believe this is intended behavior, but I could be mistaken. I also probably got the actual naming mixed up, but you should be able to tell what I mean by the examples.

Reproducible TypeScript example:

import { serialize, declarePersistable } from "serialijse"

class ThingMethod {
	thing () { return 3 };
}

class ThingPropertyFunction {
	thing = () => 3
}

declarePersistable(ThingMethod);
declarePersistable(ThingPropertyFunction)

serialize(new ThingMethod) // works
serialize(new ThingPropertyFunction) // Error: invalid typeof function undefined
Transpiled JavasScript Code
"use strict";
exports.__esModule = true;
var serialijse_1 = require("serialijse");
var ThingMethod = /** @class */ (function () {
  function ThingMethod() {
  }
  ThingMethod.prototype.thing = function () { return 3; };
  ;
  return ThingMethod;
}());
var ThingPropertyFunction = /** @class */ (function () {
  function ThingPropertyFunction() {
      this.thing = function () { return 3; };
  }
  return ThingPropertyFunction;
}());
(0, serialijse_1.declarePersistable)(ThingMethod);
(0, serialijse_1.declarePersistable)(ThingPropertyFunction);
(0, serialijse_1.serialize)(new ThingMethod); // works
(0, serialijse_1.serialize)(new ThingPropertyFunction); // Error: invalid typeof function undefined

Additionally, both of these will give an error:

import { serialize, declarePersistable } from "serialijse"

class ThingMethod {
	property = {
		thing () { return 3 }
	}
}

class ThingPropertyFunction {
	property = {
		thing: () => 3
	}
}

declarePersistable(ThingMethod);
declarePersistable(ThingPropertyFunction)

serialize(new ThingMethod) // Error: invalid typeof function undefined
serialize(new ThingPropertyFunction) // Error: invalid typeof function undefined

homomorphist avatar Nov 27 '21 00:11 homomorphist