Skip to content

Assertion function error messages are unactionable and unclear #35838

Closed
@DanielRosenwasser

Description

@DanielRosenwasser
class Foo {
    bar?: Foo

    public setBar(): asserts this is Foo & {bar: Foo}  {
        this.bar = this;
    }

    public sayHi(): string {
        return 'Hi!';
    }
}

function test() {
    let foo = new Foo();

    foo.bar = undefined;

    foo.setBar();

    if (foo.bar) {
        console.log('This should be OK: ' + foo.bar.sayHi());
    }
}

Current error

Assertions require every name in the call target to be declared with an explicit type annotation.

'foo' is declared here.

foo is declared here but... but okay so what am I supposed to do now??

Metadata

Metadata

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions