Skip to content

Currently the resulting instance has infinite "any" properties #10

@int0h

Description

@int0h

I mentioned this issue in #7

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

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

const HasB = trait(B => class extends B {
    b = 'b';
});

const Greeting = trait([HasA, HasB], B => class extends B {
    hi() {
        console.log(this.a); // a: string // Good
        console.log(this.b); // b: any    // Not good
        console.log(this.c); // c: any    // Really bad
    }
});

It looks like there is a bug in typing logic / TS compiler itself that allows accessing anything on the instance:

instance.absolutely.anything // :any 

Which is very dangerous.

There are still types for defined properties though:

this.a // string
this.b // number

I'm creating a separate issue as it seems to be quite critical type safety issue and more dangerous than the other one.

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