Typescript. Access Modifiers
public // by default
private // only inside class
protected // only inside class and its inheritors
readonly // readonly
a little bit of
public // by default
private // only inside class
protected // only inside class and its inheritors
readonly // readonly
a little bit of
ABSTRACT CLASSES EXAMPLE abstract class Prayer { abstract pray: string; abstract makeSins(): void; doPray(): string { return this.pray; } } class Muslim extends Prayer {
enum Sex { Man, Woman } class Man { name: string = «DefaultName»; family: string = «DefaultFamily»; age: number = 18; readonly sex: Sex.Man constructor(name:
enum Sex { Man, Woman } class Man { name: string = «DefaultName»; family: string = «DefaultFamily»; age: number = 18; readonly sex: Sex.Man constructor(name:
with defining data types (e.g. annotations) function add(a: number, b: number): number { return a + b; } without annotations function add2(a, b) { return
// — BOOLEAN let b: boolean = true; console.log(‘boolean ‘ + b + ‘ typeof ‘ + typeof b); // — STRING let s: string
noEmitOnError
lets write this piece of code
index.ts
let x = 0; console.log(x); var x = 1; console.log(x);
on compling with tsc index.ts
option 1
npm prettier —write «**/*.js»
option 2 add it to the scripts
{ … «scripts»: { «prettier»: «prettier —write ‘**/*.{ts,js,css,html}'» } … }
All options can be found in official documentation, so lets take a look on some of them. How to create tsconfig.json we have seen in
Lets take an example from previous post and do the following steps
Add to project tsconfig.json
and edit it like this for example, point