type User = { name: string } type Player = User & { } const nico : Player = { name: "nico" }
interface User { name: string } interface Player extends User {] } const nico : Player = { name: "nico" }
interface User {
name: string
}
interface User {
firstName: string
}
interface User {
health : number
}
const nico : User = {
name: "nico",
firstName: "oh",
health : 3
}
=> 불가능
type User = {
name : string
}
type User = {
lastName: string
}
abstract class User {
constructor(
protected firstName: string,
protected lastName: string
){}
abstract sayHi(name: string): string
abstract fullName(): string
}
class Player extends User {
fullName(){
return `${this.firstName} ${this.lastName}`
}
sayHi(name: string){
return `Hello ${name}. My name is ${this.firstName}`
}
}
interface User {
firstName: string,
lastName: string
sayHi(name: string): string
fullName(): string
}
// 추가
interface Human {
health: number
}
class Player implements User {
constructor(
public firstName:string,
public lastName: string,
public health: number
){}
fullName(){
return `${this.firstName} ${this.lastName}`
}
sayHi(name: string){
return `Hello ${name}. My name is ${this.firstName}`
}
}
type PlayerA = {
name: string
}
// type추가하기
type PlayerAA = PlayerA & {
lastName: string
}
const playerA : PlayerAA = {
name: "nico",
lastName: "oh"
}
///////////////////////////////
interface PlayerB {
name: string
}
// interface추가하기1
interface PlayerBB extends PlayerB {
lastName: string
}
// interface추가하기2
interface PlayerBB {
health: number
}
const playerB : PlayerBB = {
name: "lynn",
lastName: "kim",
health: 29
}
