mirror of
https://github.com/esiur/esiur-js.git
synced 2025-05-06 04:22:58 +00:00
25 lines
536 B
JavaScript
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;
|
|
}
|
|
} |