I
I
icetomcat2020-11-19 18:13:12
typescript
icetomcat, 2020-11-19 18:13:12

Is it possible in TypeScript to make a constant method like in C++?

Just academic interest =)
In general, TypeScript has everything you need, except for one type check.

class Foo {
    public biz = 0

    bar(this: Readonly<Foo>) {
        this.baz() // <-- Тут происходит, как бы, неявный каст типа Readonly<Foo> в просто Foo
    }

    baz(this: Foo) { // Даже если здесь я явно укажу тип для this
        this.biz = 5
    }
}

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question