Skip to content

Expose Derived type #9

@int0h

Description

@int0h

I think it might be a good idea to expose this type.

Potential use-case:

import { trait, derive, derived, Derived } from "@traits-ts/core"

const HasA = trait(B => class extends B {
    a = 'a';
});

function log(b: Derived<typeof HasA>) {
    console.log(b.a);
}

Similar can be achieved like that:

function logWithCheck(b: any) {
    if (derived(b, HasA)) {
        console.log(b.a);
    } else {
        //throw maybe?
    }
}

But then the function call would be untyped and impossible to do compile time check.

If the same can be solved somehow else I'd appreciate advice and updating docs (if it's not there yet)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions