34 lines
846 B
TypeScript
34 lines
846 B
TypeScript
import { Simplify } from "type-fest"
|
|
import { TraitAbstractMembers, TraitClass, TraitImpl, TraitInstance, expresses, trait } from "."
|
|
|
|
|
|
const PrintsHelloOnNew = trait()(Super =>
|
|
class PrintsHelloOnNew extends Super {
|
|
constructor(...args: any[]) {
|
|
super(...args)
|
|
console.log("Hello!")
|
|
}
|
|
}
|
|
)
|
|
|
|
const Identifiable = <ID>() => (
|
|
trait<{ readonly id: ID }>()(Super =>
|
|
class Identifiable extends Super {
|
|
equals(el: Identifiable) {
|
|
return this.id === el.id
|
|
}
|
|
}
|
|
)
|
|
)
|
|
|
|
|
|
type Test = Simplify<TraitInstance<ReturnType<typeof Identifiable<bigint>>>>
|
|
|
|
const appliedIdentifiable = Identifiable<bigint>().apply({} as any)
|
|
|
|
const exp = expresses(Identifiable<bigint>())
|
|
|
|
class User implements ReturnType<typeof exp.implements> {
|
|
id: bigint = -1n
|
|
}
|