First version: 20231229.0.0 (#2)
All checks were successful
continuous-integration/drone/push Build is passing
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
This commit was merged in pull request #2.
This commit is contained in:
74
src/legacy/tests.ts
Normal file
74
src/legacy/tests.ts
Normal file
@@ -0,0 +1,74 @@
|
||||
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))
|
||||
Reference in New Issue
Block a user