This commit is contained in:
45
src/tests.ts
45
src/tests.ts
@@ -1,41 +1,44 @@
|
||||
import { Implements, TraitAbstractMembers, expression, trait } from "."
|
||||
import { Implements, TraitAbstractMembers, abstract, expression, trait } from "."
|
||||
|
||||
|
||||
const PrintsHelloOnNew = trait()(Super =>
|
||||
class PrintsHelloOnNew extends Super {
|
||||
const PrintsHelloOnNew = trait(
|
||||
abstract(),
|
||||
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
|
||||
}
|
||||
const Identifiable = <ID>() => trait(
|
||||
abstract<{ readonly id: ID }>(),
|
||||
Super => class Identifiable extends Super {
|
||||
equals(el: Identifiable) {
|
||||
return this.id === el.id
|
||||
}
|
||||
)
|
||||
},
|
||||
)
|
||||
|
||||
const StatefulSubscription = trait<{
|
||||
readonly status: (
|
||||
{ _tag: "awaitingPayment" } |
|
||||
{ _tag: "active", activeSince: Date, expiresAt?: Date } |
|
||||
{ _tag: "expired", expiredSince: Date }
|
||||
)
|
||||
}>()(Super =>
|
||||
class StatefulSubscription extends Super {}
|
||||
const StatefulSubscription = trait(
|
||||
abstract<{
|
||||
readonly status: (
|
||||
{ _tag: "awaitingPayment" } |
|
||||
{ _tag: "active", activeSince: Date, expiresAt?: Date } |
|
||||
{ _tag: "expired", expiredSince: Date }
|
||||
)
|
||||
}>(),
|
||||
|
||||
Super => class StatefulSubscription extends Super {},
|
||||
)
|
||||
|
||||
interface ActiveStatefulSubscriptionAbstractMembers extends TraitAbstractMembers<typeof StatefulSubscription> {
|
||||
readonly status: { _tag: "active", activeSince: Date, expiresAt?: Date }
|
||||
}
|
||||
|
||||
const ActiveStatefulSubscription = trait<ActiveStatefulSubscriptionAbstractMembers>()(Super =>
|
||||
class ActiveStatefulSubscription extends Super {}
|
||||
const ActiveStatefulSubscription = trait(
|
||||
abstract<ActiveStatefulSubscriptionAbstractMembers>(),
|
||||
Super => class ActiveStatefulSubscription extends Super {},
|
||||
)
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user