Created
September 6, 2021 13:01
-
-
Save guidani/ff647a87a1ef5f15a3dac70ba73db4fe to your computer and use it in GitHub Desktop.
Typescript multipla herança
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export interface Person { | |
name: string; | |
age: number; | |
} | |
export interface Job { | |
jobName: string; | |
jobSalary: number; | |
} | |
export interface Worker extends Person, Job{ | |
person: Person; | |
job: Job; | |
} | |
export class Worker implements Worker{ | |
name: string; | |
age: number; | |
jobName: string; | |
jobSalary: number; | |
constructor(name: string, age: number, jName: string, jSalary: number){ | |
this.name = name; | |
this.age = age; | |
this.jobName = jName; | |
this.jobSalary = jSalary; | |
} | |
} |
interface Person {
name: string;
age: number;
// greeting(): void;
}
interface Job {
jobName: string;
jobSalary: number;
}
export interface Worker extends Person, Job{
person: Person;
job: Job;
}
export class Worker implements Worker{
constructor(person: Person, job: Job){
this.name = person.name;
this.age = person.age;
this.jobName = job.jobName;
this.jobSalary = job.jobSalary;
}
workerInformations(worker: Worker){
console.log(`Worker name: ${worker.name}\nWorker job: ${worker.jobName}`);
}
}
let person = {
name: "José",
age: 25
}
let job = {
jobName: "Dev",
jobSalary: 1234
}
let w = new Worker(person, job);
w.workerInformations(w)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Objetivo do código, criar um "trabalhador" que seja uma pessoa e que tenha um emprego.