-
-
Save seungha-kim/c52dc56f6c39487b52a2da0eab2aabe2 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const code: string = 'en' // string? |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type LanguageCode = 'ko' | 'en' | 'ja' | 'zh' | 'es' | |
const code: LanguageCode = 'ko' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const korean = 'ko' | |
const english = 'en' | |
const japanese = 'ja' | |
const chinese = 'zh' | |
const spanish = 'es' | |
// 이렇게 하면 언어 코드가 위아래에 중복되고 | |
type LanguageCode = 'ko' | 'en' | 'ja' | 'zh' | 'es' | |
// 이렇게 하면 코드가 너무 길어집니다 | |
// type LanguageCode = typeof korean | typeof english | typeof japanese | typeof chinese | typeof spanish | |
const code: LanguageCode = korean |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export enum LanguageCode { | |
korean = 'ko', | |
english = 'en', | |
japanese = 'ja', | |
chinese = 'zh', | |
spanish = 'es', | |
} | |
// 여기서 | |
// LanguageCode.korean === 'ko' | |
// (의미상) LanguageCode === 'ko' | 'en' | 'ja' | 'zh' | 'es' | |
const code: LanguageCode = LanguageCode.korean |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const keys = Object.keys(LanguageCode) // ['korean', 'english', ...] | |
const values = Object.values(LanguageCode) // ['ko', 'en', ...] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const LanguageCode = { | |
korean: 'ko', | |
english: 'en', | |
japanese: 'ja', | |
chinese: 'zh', | |
spanish: 'es', | |
} as const | |
// 속성 값을 변경할 수 없음 | |
// 속성의 타입으로 리터럴 타입이 지정됨 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment