typescript 개념 정리
let user: {
id?: number;
name: string;
} = {
id: 1,
name: "abc",
};
user.id;
let dog: {
name: string;
color: string;
} = {
name: "돌돌이",
color: "brown"
};
user.id;
dog.name;
type User = {
id: number;
name: string;
nickname: string;
birth: string;
bio: string;
location: string;
}
function func() {
type User = {};
}
let user1 : User = {
id: 1,
name: "제임스",
nickname: "james",
birth: "1997.01.07",
bio: "hi",
location: "부천시"
};
let user2 : User = {
id: 2,
name: "티모시",
nickname: "timothee",
birth: "1997.01.07",
bio: "hi",
location: "부천시"
};
type CountryCodes = {
[key : string] : string;
Korea: string;
}
let contryCodes: CountryCodes = {
Korea : 'ko',
UnitedState: 'us',
}
type CountryNumberCodes = {
[key: string] : number;
Korea: number;
};
let CounrtyNumberAndStringCodes: CountryNumberCodes = {
Korea: 410,
};
enum Role {
ADMIN,
USER,
GUEST,
}
enum Language {
korean = "ko",
english = "en",
}
const user11 = {
name: "abc",
role: Role.ADMIN,
language: Language.korean,
}
const user12 = {
name: "def",
role: Role.USER,
language: Language.english,
}
const user13 = {
name: "ghi",
role: Role.GUEST,
}
console.log(user11, user12, user13);