μλ
νμΈμ, μ λ μ΅κ·Όμ TypeScriptλ₯Ό μ¬μ©νκΈ° μμνμ΅λλ€. λμκ² λ§€μ° μ μ©ν μΈμ΄μ
λλ€. :)
그건 κ·Έλ κ³ , λλ μ¬κΈ° https://www.typescriptlang.org/docs/handbook/basic-types.htmlμ String Type
μ λν μμ΅μμ μμ΅λλ€.
TypeScript λ²μ :
1.8.10
μνΈ
_hello.ts_
let name: string = "bob";
μ»΄νμΌ ν λλ§λ€ μ»΄νμΌλ¬λ λ€μμ λ΄ λ³΄λ λλ€.
$ tsc hello.ts
../../usr/local/lib/node_modules/typescript/lib/lib.d.ts(16757,13): error TS2451: Cannot redeclare block-scoped variable 'name'.
hello.ts(1,5): error TS2451: Cannot redeclare block-scoped variable 'name'.
_hello.ts_
let aname: string = "bob";
lib.d.ts
μ μΌλΆλ₯Ό μ½μμΌλ©° declare var name: string;
μμ΅λλ€. λ°λΌμ μ»΄νμΌλ¬μμ μ€λ₯κ° λ°μνλ€λ κ²μ μ΄ν΄ν μ μμ΅λλ€. κ·Έλ¬λ TypeScriptμμ name
λ³μλ₯Ό μ¬μ©ν μμλ κ°λ
μ 무μμ
λκΉ?
κ·Έλ¦¬κ³ μλνμ§ μλ νν 리μΌμ μ’μ§ μλ€κ³ μκ°ν©λλ€ :(
μλλ©΄ λμκ² λ¬Έμ κ° μμ΅λκΉ? λλ λλ΅μ μ¬μνκ³ μΆλ€ :)
_global scope_μ name
λΌλ λ³μκ° μ΄λ―Έ μκΈ° λλ¬Έμ
λλ€. λΈλΌμ°μ console.log(name)
μμ μλν΄ λ³΄λ©΄ undefined
λμ λΉ λ¬Έμμ΄ (λλ λ€λ₯Έ λ¬Έμμ΄)μ΄ νμλ©λλ€.
_module_ λλ namespace
μ΄λ¦ λ³μ μ
λ ₯ : https://basarat.gitbooks.io/typescript/content/docs/project/modules.html
μ΄ λ³μμ λν λ¬Έμ : https://developer.mozilla.org/en-US/docs/Web/API/Window/name : rose :
λΏ‘λΏ‘
λ΅λ³ μ£Όμ
μ κ°μ¬ν©λλ€. κ·Έλ° μλ―Έκ° μμ΅λλ€ ...
μ μ λ²μμ μ΄λ―Έ name
λ³μκ° μλμ§ λͺ°λμ΅λλ€. :)
μλ
νμΈμ.
λ¬Έμλ₯Ό μμ ν΄μ£Όμ
μ κ°μ¬ν©λλ€ :)
κ°μ₯ μ μ©ν λκΈ
_global scope_μ
name
λΌλ λ³μκ° μ΄λ―Έ μκΈ° λλ¬Έμ λλ€. λΈλΌμ°μ console.log(name)
μμ μλν΄ λ³΄λ©΄undefined
λμ λΉ λ¬Έμμ΄ (λλ λ€λ₯Έ λ¬Έμμ΄)μ΄ νμλ©λλ€.κ³ μΉλ€
_module_ λλ
namespace
μ΄λ¦ λ³μ μ λ ₯ : https://basarat.gitbooks.io/typescript/content/docs/project/modules.html