[TypeScript] ํƒ€์ž… ํ˜ธํ™˜(Type Compatibility)

๐Ÿ“„ ํƒ€์ž… ํ˜ธํ™˜(Type Compatibility)

ํƒ€์ž… ํ˜ธํ™˜์€ ํƒ€์ž…์Šคํฌ๋ฆฝํŠธ ์ฝ”๋“œ์—์„œ ํŠน์ • ํƒ€์ž…์ด ๋‹ค๋ฅธ ํƒ€์ž…์— ์ž˜ ๋งž๋Š”์ง€ ์•Œ๋ ค์ฃผ๋Š” ํŠน์ง•์ž…๋‹ˆ๋‹ค.

interface Developer {
  name: string;
  skill: string;
}

interface Person {
  name: string;
}

var developer: Developer;
var person: Person;

developer = person; // Error
person = developer;

ํƒ€์ž… ํ˜ธํ™˜์€ ๋ถ€๋ถ„ ์ง‘ํ•ฉ ๊ฐœ๋…์œผ๋กœ ์ ‘๊ทผํ•˜๋ฉด ์ดํ•ดํ•˜๊ธฐ ์‰ฝ์Šต๋‹ˆ๋‹ค.

์—๋Ÿฌ๊ฐ€ ๋‚œ ์ด์œ ๋Š” developer(์™ผ์ชฝ)๊ฐ€ ๋” ๋งŽ์€ ํƒ€์ž…์„ ๊ฐ€์ง€๊ณ  ์žˆ๊ธฐ ๋•Œ๋ฌธ์ž…๋‹ˆ๋‹ค.

์˜ค๋ฅธ์ชฝ์˜ ํƒ€์ž…์ด ๋” ๋งŽ์•„์•ผ ํƒ€์ž… ํ˜ธํ™˜์ด ์ด๋ฃจ์–ด์งˆ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

์ถœ์ฒ˜

Leave a comment