2
0
mirror of https://github.com/esiur/esiur-js.git synced 2025-05-06 04:22:58 +00:00
esiur-js/src/Data/Nullable.js
2022-09-03 03:08:57 +03:00

25 lines
536 B
JavaScript

export default class Nullable {
static cache = { };
static getType(nullableType){
return nullableType.constructor.type;
}
static of(type){
if (type.constructor.isNullable)
return type;
if (Nullable.cache[type] != null)
return Nullable.cache[type];
let c = class extends type{}
Object.defineProperty(c, "isNullable", {value: true});
Object.defineProperty(c, "type", {value: type});
Nullable.cache[type] = c;
return c;
}
}