All checks were successful
continuous-integration/drone/push Build is passing
Co-authored-by: Julien Valverdé <julien.valverde@mailo.com> Reviewed-on: https://git.jvalver.de/Thilawyn/thilatrait/pulls/2
75 lines
1.5 KiB
TypeScript
75 lines
1.5 KiB
TypeScript
import { AbstractClass } from "type-fest"
|
|
import { expresses } from "./trait"
|
|
|
|
|
|
function inspectClass(class_: AbstractClass<any, any>) {
|
|
Object.getOwnPropertyNames(class_).forEach(name => {
|
|
console.log(
|
|
"[static]",
|
|
name,
|
|
Object.getOwnPropertyDescriptor(class_, name)
|
|
)
|
|
})
|
|
|
|
Object.getOwnPropertyNames(class_.prototype).forEach(name => {
|
|
console.log(
|
|
"[prototype]",
|
|
name,
|
|
Object.getOwnPropertyDescriptor(class_.prototype, name)
|
|
)
|
|
})
|
|
}
|
|
|
|
|
|
abstract class Identified<ID> {
|
|
abstract id: ID
|
|
|
|
equals(el: Identified<ID>) {
|
|
return this.id === el.id
|
|
}
|
|
|
|
// initializer() {
|
|
// console.log("Identified initializer")
|
|
// }
|
|
}
|
|
|
|
class ImplementsIdentifiable<ID> extends Identified<ID> {
|
|
id!: ID
|
|
}
|
|
|
|
|
|
abstract class Permissible {
|
|
static readonly defaultPermissions: string[] = []
|
|
permissions: string[] = []
|
|
// permissions!: string[]
|
|
|
|
constructor() {
|
|
console.log("Permissible constructor")
|
|
}
|
|
|
|
initializer() {
|
|
console.log("Permissible initializer")
|
|
this.permissions = []
|
|
}
|
|
}
|
|
|
|
|
|
class User extends expresses(
|
|
Identified as typeof Identified<bigint>,
|
|
// Identified<string>,
|
|
Permissible,
|
|
) {
|
|
readonly id: bigint
|
|
|
|
constructor(id: bigint) {
|
|
super()
|
|
this.id = id
|
|
}
|
|
}
|
|
|
|
const user1 = new User(BigInt(1))
|
|
const user2 = new User(BigInt(2))
|
|
|
|
console.log(user1)
|
|
console.log(user1.equals(user2))
|