Skip to content

Commit

Permalink
fix: combineVowels 리턴 타입 보강 (#308)
Browse files Browse the repository at this point in the history
* feat: combineVowels 리턴 타입 보강

* Create great-phones-type.md

---------

Co-authored-by: 박찬혁 <[email protected]>
  • Loading branch information
skiende74 and okinawaa authored Jan 6, 2025
1 parent 42c9eb3 commit 7aac3ff
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
5 changes: 5 additions & 0 deletions .changeset/great-phones-type.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"es-hangul": patch
---

feat: combineVowels 리턴 타입 보강
12 changes: 7 additions & 5 deletions src/combineVowels/combineVowels.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,11 @@ import { DISASSEMBLED_VOWELS_BY_VOWEL } from '@/_internal/constants';
* combineVowels('ㅗ', 'ㅐ') // 'ㅙ'
* combineVowels('ㅗ', 'ㅛ') // 'ㅗㅛ'
*/
export function combineVowels(vowel1: string, vowel2: string) {
return (
Object.entries(DISASSEMBLED_VOWELS_BY_VOWEL).find(([, value]) => value === `${vowel1}${vowel2}`)?.[0] ??
`${vowel1}${vowel2}`
);

type Invert<T extends Record<string, string>> = { [K in keyof T as T[K]]: K };
type CombineVowel = Invert<typeof DISASSEMBLED_VOWELS_BY_VOWEL>;

export function combineVowels<V1 extends string, V2 extends string>(vowel1: V1, vowel2: V2) {
return (Object.entries(DISASSEMBLED_VOWELS_BY_VOWEL).find(([, value]) => value === `${vowel1}${vowel2}`)?.[0] ??
`${vowel1}${vowel2}`) as `${V1}${V2}` extends keyof CombineVowel ? CombineVowel[`${V1}${V2}`] : `${V1}${V2}`;
}

0 comments on commit 7aac3ff

Please sign in to comment.