TypeScript. Classes

Home » Tutorials » JavaScript » TypeScript. Classes
In this lesson we will talk about classes in TypeScript
In this video we’ll discuss

  • Access modifiers (public, protected, private)
  • Inheritance
  • Readonly class properties
  • Getters and setters
  • Abstract classes
Code lesson
abstract class Programmer {

	fullName = 'Full name';

	abstract printFullName(): void;
}


class John {

	private _name: string = 'Kamil';
	protected lang = 'JS';
	private _jobPlace = 'Apple';
	fullName = 'Kamil Abzalov';

	private readonly _restApi = 'http://example.com/api';

	constructor() {

	}

	sayHello(): void {
		console.log(this.name + " hello");
	}

	static printArrLength() {
		const nums: Array<number> = [1,2,3,4];
		console.log(nums.length);
	}

	get name() {
		return this._name + " Abzalov";
	}

	set name(newName: string) {
		if (newName.length > 10) {
			this._name = newName;
		}
	}

}

class Kamil extends Programmer {
	constructor() {
		super();
	}

	getLanguage() {
		// console.log(this.lang);
	}

	printFullName() {
		console.log(this.fullName);
	}
}

let kamil = new Kamil();
// console.log(kamil.name);
// kamil.sayHello();
kamil.getLanguage();

John.printArrLength();

kamil.printFullName();

0 Comments

Submit a Comment

Your email address will not be published. Required fields are marked *

Подписаться на рассылку

Будьте в курсе - получайте последние статьи на свой email

Ваша подписка успешно оформлена

Pin It on Pinterest

Share This