Modifier of access "private" in TypeScript

2

In most of the examples I encounter in TypeScript, I see that the attributes of the class do not use the private access modifier. Is it a matter of design or is there any difference in how Java works?

export class Aluno {
    codigo:number;
    nome:string;
}
    
asked by anonymous 23.11.2018 / 10:42

1 answer

3

Let's agree that the term attribute is wrong, you mean field . TypeScript has its public members by default, so in the absence of anything explicit access is general.

The fact that you do not see private is only a coincidence, it's possible. There is a current that does not follow this "object-oriented" fashion that everything has to be private, even though people do not even understand why they are doing it. TS is a script language, as the name itself says, so it is much less necessary to follow object-oriented rules than in other languages. But if you have a good reason you can establish that any member is private.

It's a bit different from Java, which by the way people find it private by default and it's not.

    
23.11.2018 / 11:20