๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ
Frontend/TypeScript

[ ํƒ€์ž…์Šคํฌ๋ฆฝํŠธ(TypeScript) ] interface ์‚ฌ์šฉํ•˜์ง€ ์•Š๊ณ  ์จ๋ณด๊ธฐ ์‚ฌ์šฉํ•˜๊ณ  ์จ๋ณด๊ธฐ

by YWTechIT 2021. 7. 7.
728x90

๐Ÿ“ interface ์‚ฌ์šฉํ•˜์ง€ ์•Š๊ณ  ์จ๋ณด๊ธฐ ์‚ฌ์šฉํ•˜๊ณ  ์จ๋ณด๊ธฐ

// do not use Interface
const getMathScore = (scoreObj: {math: number}): number => {
    return scoreObj.math
}

const myScore = {korean: 85, math: 95, english: 87}
const myMathScore = getMathScore(myScore);

console.log(myMathScore)
๐Ÿ‘‰๐Ÿฝ 95

// do Interface
interface PhysicalValue {
    physical: number;
}

const getPhysicalScore = (scoreObj: PhysicalValue) => {
    return scoreObj.physical
}

const yourScore = {music: 87, art: 69, physical: 92}
const yourPhysicalScore = getPhysicalScore(yourScore);

console.log(yourPhysicalScore)
๐Ÿ‘‰๐Ÿฝ 92
๋ฐ˜์‘ํ˜•

๋Œ“๊ธ€