“This is the second day of my participation in the Gwen Challenge in November. See details: The Last Gwen Challenge in 2021”

Interface Interface type

Accepts only strings or methods, unlike the type alias of Type, which can declare a type directly

Interface Person {// readonly name: string // readonly Read-only type, not writable name: string age? : number // ? [propName: string]: any [propName: string]: any Interface Teacher extends Person (): string} interface Sayhi { string): string } const getPersonName = (person: Person): void => { console.log(person.name) } const setPersonName = (person: Person, name: string): void => { person.name = name } const person = { name: 'dell', sex: "male", say() { return "say hello" } } getPersonName(person) setPersonName(person, 'lee') class User implements Person {// Define the User class to implements. "lee" say() { return "say hello" } } const say: Sayhi = (word: string) => { return word }Copy the code

Class inheritance

class person { name = "dell" getName() { return this.name } } class Teacher extends person { getTeacherName() { return GetName () {return super.getName() + "lee"}} const person = new Teacher() console.log(person.getTeacherName()) // lee console.log(person.getName()) // dellleeCopy the code

There are three access types: private, protected and public

Public Public call method

Allows calls both inside and outside a class

Class Person {public name: String public sayHi() {console.log(this.name) // console.log("hi")}} // Called outside the class const person = new Person() person.name = "dell" console.log(person.name) // dell person.sayHi() // hiCopy the code

private

It is only allowed to be called inside a class. It is an error to call outside the class

Class Person {private name: private name: private name: private name: private name: private name: private name: private name: String public sayHi() {console.log(this.name) // Called inside the class dell console.log("hi")}} // called outside the class const person = new Person() person.name = "dell" // error: cannot compile console.log(person.name) // error: cannot compile person.sayhi () // hiCopy the code

protected

In contrast to private, it is only allowed within classes and in inherited subclasses

// private, protected, Public Three access types // public allows me to be called inside and outside a class // private allows me to be used inside a class name: String public sayHi() {console.log(this.name)}} class Teacher extends Person {console.log("hi")}} Public sayBye() {console.log(this.name) // dell}} const person = new person () person.name = "dell" Unable to compile console.log(person.name) // error, unable to compile person.sayhi () // hiCopy the code

The last

Public number: small he growth, the Buddha department more text, are their own once stepped on the pit or is learned things

Interested little partners welcome to pay attention to me oh, I was: he Small Life. Everybody progress duck together