TypeScript Basic - ChoDragon9/posts GitHub Wiki
https://www.typescriptlang.org/docs/handbook/basic-types.html
νμ μ§μ
let name1 = 'John Smith';
let name2 : string = 'John Smith';
let salary : number;
let name : string = 'Alex';
let isValid : boolean;
let customerName : string = null;
λ³μλ ν¨μμ μΈμμ νμ μ λͺ μνμ§ μμΌλ©΄ TypeScript μ»΄νμΌλ¬λ μ΄ λ³μκ° any νμ μ μ§μ ν κ²μΌλ‘ κ°μ£Όνλ€.
ν¨μ
Javascript
function calcTax (state, income, dependents) {
if (state === 'NY') {
...
} else {
...
}
}
TypeScript
function calcTax (state : string, income : number, dependents : number) : number {
if (state === 'NY') {
...
} else {
...
}
}
μΈμ κΈ°λ³Έκ°
κΈ°λ³Έκ°μ΄ μλ μΈμλ μΈμλ€ μ€μ λ§μ§λ§μ μμ΄μΌν¨.
function calcTax (dependents : number, state : string = 'NY') : number {
if (state === 'NY') {
...
} else {
...
}
}
μ΅μ μΈμ
function calcTax (dependents : number, state? : string = 'NY') : number {
if (state === 'NY') {
...
} else {
...
}
}