TypeScript๋Š” ๋‚ด $#!% ๐Ÿ’ฉ ๋ชฉ๋ก์— ์žˆ์—ˆ์Šต๋‹ˆ๋‹ค.

2619 ๋‹จ์–ด discusswebdevtypescriptjavascript

์ž๋ฐ”์Šคํฌ๋ฆฝํŠธ(JS)



JS - Netscape์˜ Brendan Eich๊ฐ€ ๊ฐœ๋ฐœํ•œ ๋†’์€ ์ˆ˜์ค€์˜ ECMAScript ํ•ด์„/์ ์‹œ ์ปดํŒŒ์ผ ํ”„๋กœ๊ทธ๋ž˜๋ฐ ์–ธ์–ด์ž…๋‹ˆ๋‹ค. Java๊ณผ ํ˜ผ๋™ํ•˜์ง€ ๋งˆ์‹ญ์‹œ์˜ค.

JavaScript was initially created to โ€œmake web pages aliveโ€.


  • ์ž˜ ์•Œ๋ ค์ง„ - JS๋Š” ์ธํ„ฐ๋„ท
  • ๋งŒํผ์ด๋‚˜ ์˜ค๋ž˜๋˜์—ˆ์Šต๋‹ˆ๋‹ค.
  • JS๋Š” OOP(๊ฐ์ฒด ์ง€ํ–ฅ ํ”„๋กœ๊ทธ๋ž˜๋ฐ) ์–ธ์–ด์ž…๋‹ˆ๋‹ค
  • .
  • JS๋Š” ๋‹จ์ผ ์Šค๋ ˆ๋“œ์ž…๋‹ˆ๋‹ค
  • .
  • ๊ทธ๋Ÿฌ๋‚˜ JS๋Š” ์•ฝํ•˜๊ณ  ๋™์ ์œผ๋กœ ์ž…๋ ฅ๋ฉ๋‹ˆ๋‹ค
  • .

    ๐Ÿ‘ฉ๐Ÿฝโ€๐Ÿ’ป(๋‚˜): ์ž˜ ์ง€๋‚ด์š”JavaScript , ์„ธ๊ณ„์—์„œ ๊ฐ€์žฅ ์ธ๊ธฐ ์žˆ๋Š” ์Šคํฌ๋ฆฝํŒ… ์–ธ์–ด ์ค‘ ํ•˜๋‚˜์— ๋Œ€ํ•ด ๋ฌด์Šจ ๋ง์„ ๋” ํ•ด์•ผ ํ• ๊นŒ์š”? ๐ŸŒŽ(์„ธ๊ณ„): TypeScript ๋˜๋Š” GTFO์— ๋Œ€ํ•ด ์•Œ์•„๋ณด์„ธ์š”.

    ๊ทธ๋ž˜์„œ TypeScript๋ฅผ ๋ฐฐ์šฐ๊ธฐ ์‹œ์ž‘ํ–ˆ์Šต๋‹ˆ๋‹ค. ๊ฑฐ์ง“๋ง ์•ˆํ•˜๊ณ  ์ฒ˜์Œ์—๋Š” ๋„ˆ๋ฌด ์•„ํŒ ์–ด์š”. ๋‚˜๋Š” JS๋ฅผ ์ถฉ๋ถ„ํžˆ ์˜ค๋ž˜ ์‚ฌ์šฉํ•˜์ง€ ์•Š์•˜๊ณ , JS๋ฅผ ์ถฉ๋ถ„ํžˆ ์ดํ•ดํ•˜์ง€ ์•Š์•˜์œผ๋ฉฐ, TS์™€ ๊ฐ™์€ ๊ฒƒ์„ ๊ฐ์‚ฌํ•  ๋งŒํผ ๋ชจ๋“  ๋ฐ”๋ณด ๊ฐ™์€ JS ์˜ค๋ฅ˜/๋ธŒ๋ผ์šฐ์ € ํ˜ธํ™˜์„ฑ ๋ฌธ์ œ์— ์ถฉ๋ถ„ํžˆ ์งœ์ฆ์„ ๋ƒˆ์Šต๋‹ˆ๋‹ค.

    Thus, TS was very much so on my ๐Ÿ’ฉ list, but I have since seen the light.



    ํƒ€์ž…์Šคํฌ๋ฆฝํŠธ(TS)



    TS - JavaScript๋ฅผ ๊ธฐ๋ฐ˜์œผ๋กœ Microsoft์—์„œ ๊ฐœ๋ฐœํ•œ ๊ฐ•๋ ฅํ•œ ์œ ํ˜•์˜ ํ”„๋กœ๊ทธ๋ž˜๋ฐ ์–ธ์–ด๋กœ ๋ชจ๋“  ๊ทœ๋ชจ์—์„œ ๋” ๋‚˜์€ ๋„๊ตฌ๋ฅผ ์ œ๊ณตํ•ฉ๋‹ˆ๋‹ค.

    ์—๋””ํ„ฐ ์ฒดํฌ



    TS๊ฐ€ ๋งˆ์Œ์— ๋“ค์ง€ ์•Š์œผ๋ฉด ์ปดํŒŒ์ผ๋˜์ง€ ์•Š๊ธฐ ๋•Œ๋ฌธ์— ๊ฐ‘์ž๊ธฐ ๋””๋ฒ„๊น…์€ ํŽธ์ง‘๊ธฐ ๊ฒ€์‚ฌ๋กœ ์•…๋ชฝ์ด ์•„๋‹™๋‹ˆ๋‹ค.

    const user = {
      id: l334,
      firstName: "Nicole",
      lastName: "Nobles",
      job: "Web developer",
    }
    
    console.log(user.name)
    


    JS๋Š” ์‚ฌ์šฉ์ž์—๊ฒŒ ์ด๋ฆ„ ์†์„ฑ์ด ์—†๋‹ค๋Š” ๊ฒฝ๊ณ ๋ฅผ ์•Œ์ง€ ๋ชปํ•ฉ๋‹ˆ๋‹ค.

    ํ•˜์ง€๋งŒ TS์—์„œ๋Š” ์˜ค๋ฅ˜๊ฐ€ ๋ฐœ์ƒํ•ฉ๋‹ˆ๋‹ค.Property 'name' does not exist on type { firstName: string; lastName: string; job: string }

    ์ž๋™ ์™„์„ฑ



    ๋” ์ด์ƒ ๊ฐœ์ฒด์— ์–ด๋–ค ์†์„ฑ์ด ์žˆ๋Š”์ง€ ์ถ”์ธกํ•˜์ง€ ์•Š์•„๋„ ๋ฉ๋‹ˆ๋‹ค.

    ์ธํ„ฐํŽ˜์ด์Šค



    ์‚ฌ์šฉ์ž ์ธํ„ฐํŽ˜์ด์Šค๋ฅผ ๋งŒ๋“  ๊ฒฝ์šฐ ๊ฐœ์ฒด์— ํ•„์š”ํ•œ ์†์„ฑ์„ ์ถ”๊ฐ€/์ œ๊ฑฐํ•  ์ˆ˜ ์—†์Šต๋‹ˆ๋‹ค.

    *์ฐธ๊ณ : ์†์„ฑ ๋’ค์— ?๋ฅผ ์ถ”๊ฐ€ํ•˜๋ฉด ์„ ํƒ ์‚ฌํ•ญ์ด ๋ฉ๋‹ˆ๋‹ค.

    interface User {
      id: number
      firstName: string
      lastName: string
      job: string
      remote?: boolean
    }
    
    function updateUser(id: number, update: Partial<User>) {
      const data = getUser(id)
      const user = { ...data, ...update, city: "Hachiลji" }
      saveUser(id, user)
    }
    


    TS๋Š” '์‚ฌ์šฉ์ž' ์ธํ„ฐํŽ˜์ด์Šค์— '๋„์‹œ'๊ฐ€ ์กด์žฌํ•˜์ง€ ์•Š๋Š”๋‹ค๊ณ  ์ •๋‹นํ•˜๊ฒŒ ๋ถˆํ‰ํ•  ๊ฒƒ์ž…๋‹ˆ๋‹ค.

    ์ด๊ฒƒ์€ TS ๋น™์‚ฐ์˜ ์ผ๊ฐ์— ๋ถˆ๊ณผํ•ฉ๋‹ˆ๋‹ค. ๋‚ด ๋ง์„ ๋ฏฟ์ง€ ๋งˆ์‹ญ์‹œ์˜ค. ์„ค๋ช…์„œhere๋ฅผ ํ™•์ธํ•˜์‹ญ์‹œ์˜ค.

    ๊ฒฐ๋ก 



    ์ ์ ˆํ•œ ๊ธฐํšŒ๊ฐ€ ์ฃผ์–ด์ง€๋ฉด TypeScript๋Š” ํŽธ์ง‘๊ธฐ ํ™•์ธ, ์ž๋™ ์™„์„ฑ ๋ฐ ์ธํ„ฐํŽ˜์ด์Šค ๊ธฐ๋Šฅ์„ ํ†ตํ•ด ์‹œ๊ฐ„๊ณผ ํž˜๋“  ๊ณ ํ†ต์„ ์ค„์ด๋Š” ๋ฐ ๋†€๋ž๋„๋ก ๋„์›€์ด ๋˜์—ˆ์Šต๋‹ˆ๋‹ค. ๋‚˜๋Š” ๋•Œ๋•Œ๋กœ ๊ฑฐ์ง“๋ง์„ ํ•˜์ง€ ์•Š๊ณ  ๊ทธ๋ƒฅ ๋•Œ๋ฆฌ๊ณ any ํ•˜๋ฃจ๋ผ๊ณ  ๋ถ€๋ฅด์ง€๋งŒ, ํ”„๋กœ์ ํŠธ์˜ ๋‚˜๋จธ์ง€ ๋ถ€๋ถ„์ฒ˜๋Ÿผ ํƒ€์ดํ•‘๋  ๋•Œ๊นŒ์ง€ ๊ทธ๊ฒƒ์€ ๋‚˜๋ฅผ ์ž ์‹ํ•ด ๋ฒ„๋ฆฝ๋‹ˆ๋‹ค.

    ๊ทธ๋Ÿฌ๋‹ˆ ์นจ์ฐฉํ•˜๊ณ  Type(Script)๋ฅผ ์ผœ์‹ญ์‹œ์˜ค. ์ฝ์–ด ์ฃผ์…”์„œ ๊ฐ์‚ฌํ•ฉ๋‹ˆ๋‹ค! ๐Ÿ˜Š

    ์ข‹์€ ์›นํŽ˜์ด์ง€ ์ฆ๊ฒจ์ฐพ๊ธฐ