Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

2 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

Typed Korean

If you can write TypeScript, you can understand Korean!

Open in StackBlitz

demo

New: Interactive Playground โ†’ โ€” an in-browser TypeScript editor where the compiler resolves conjugations live, plus a Verb Lab, Adjective Lab, Phrase Builder, and Sentence Gallery. (source ยท run locally with cd playground && pnpm install && pnpm dev)

Typed Korean is a TypeScript type-level library that enables the expression of complete Korean sentences through the type system. It creates a domain-specific language (DSL) based on Korean grammar rules, allowing a subset of grammatically correct natural language to be written and verified using TypeScript's compiler.

This project also explores an intermediate format for AI in language learning. For example, LLMs could return grammar analysis of Korean sentences using this format instead of JSON, enabling verification through TypeScript's type checker to improve correctness.

๐Ÿ“– Want to learn more? Check out our detailed blog post which explains how the TypeScript type system can be used to learn Korean grammar from the ground up. The article starts with basic programming concepts and gradually builds up to complex Korean grammatical structures like conditional sentences and interrogative phrases.

// Define the proper noun "ใƒ’ใƒณใƒกใƒซ"
type ใƒ’ใƒณใƒกใƒซ = ProperNoun<"ใƒ’ใƒณใƒกใƒซ">;

// Define ใ™ใ‚‹ verb
type ใ™ใ‚‹ = IrregularVerb & { dictionary: "ใ™ใ‚‹" };

// Create the ใใ†ใ—ใŸ pattern (past form of ใใ†ใ™ใ‚‹)
type ใใ†ใ—ใŸ = DemonstrativeAction<Demonstrative & "ใใ†", ใ™ใ‚‹, "Ta">;

// Create the conditional phrase "ใƒ’ใƒณใƒกใƒซใชใ‚‰ใใ†ใ—ใŸ"
type ใƒ’ใƒณใƒกใƒซใชใ‚‰ใใ†ใ—ใŸ = ConditionalPhrase<ใƒ’ใƒณใƒกใƒซ, "ใชใ‚‰", ใใ†ใ—ใŸ>;

// Type checking examples
const properExample: ใƒ’ใƒณใƒกใƒซใชใ‚‰ใใ†ใ—ใŸ = "ใƒ’ใƒณใƒกใƒซใชใ‚‰ใใ†ใ—ใŸ"; // "If it were Himmel, he would do so"
// ๅฆ‚ๆžœๆ˜ฏ่พ›็พŽๅฐ”็š„่ฏ๏ผŒไป–ไนŸไผš่ฟ™ไนˆๅš็š„

๐Ÿค– Verb System

Verb Classes

Korean verbs are categorized into three main classes:

  1. Godan Verbs (ไบ”ๆฎตๅ‹•่ฉž) - Also known as "Group 1" or "u-verbs"

    • Endings: ใ†, ใ, ใ, ใ™, ใค, ใฌ, ใถ, ใ‚€, ใ‚‹
    • Examples: ่ฉฑใ™ (hanasu - to speak), ๆ›ธใ (kaku - to write)
  2. Ichidan Verbs (ไธ€ๆฎตๅ‹•่ฉž) - Also known as "Group 2" or "ru-verbs"

    • Always end with ใ‚‹
    • Examples: ้ฃŸในใ‚‹ (taberu - to eat), ่ฆ‹ใ‚‹ (miru - to see)
  3. Irregular Verbs (ไธ่ฆๅ‰‡ๅ‹•่ฉž) - Only two main verbs

    • ใ™ใ‚‹ (suru - to do)
    • ๆฅใ‚‹ (kuru - to come)

Verb Conjugation Forms

The system supports these conjugation forms:

  • Dictionary (Dictionary form)
  • Masu (Polite form)
  • Te (Te form)
  • Ta (Past form)
  • Nai (Negative form)
  • Potential (Potential form)
  • Passive (Passive form)
  • Causative (Causative form)
  • Volitional (Volitional form)
  • Imperative (Imperative form)
  • Conditional (Conditional form)
  • Hypothetical (Hypothetical form)
type ่ฒทใ† = GodanVerb & { stem: "่ฒท"; ending: "ใ†" };
type ่ฒทใ†Te = ConjugateVerb<่ฒทใ†, "Te">; // ่ฒทใฃใฆ
type ่ฒทใ†Ta = ConjugateVerb<่ฒทใ†, "Ta">; // ่ฒทใฃใŸ

type ้ฃŸในใ‚‹ = IchidanVerb & { stem: "้ฃŸใน"; ending: "ใ‚‹" };
type ้ฃŸในใ‚‹Te = ConjugateVerb<้ฃŸในใ‚‹, "Te">; // ้ฃŸในใฆ
type ้ฃŸในใ‚‹Ta = ConjugateVerb<้ฃŸในใ‚‹, "Ta">; // ้ฃŸในใŸ

๐ŸŽจ Adjective System

Korean adjectives are categorized into two main classes:

  1. I-Adjectives (ใ„ๅฝขๅฎน่ฉž) - End with ใ„

    • Examples: ใ„ใ„ (good), ๆฅฝใ—ใ„ (fun), ้ซ˜ใ„ (expensive)
  2. Na-Adjectives (ใชๅฝขๅฎน่ฉž) - Require ใช when modifying nouns

    • Examples: ็ถบ้บ— (pretty), ้™ใ‹ (quiet), ๅฅฝใ (liked)

Adjective Conjugation Forms

The system supports these conjugation forms for adjectives:

  • Basic (Basic form)
  • Polite (Polite form)
  • Past (Past form)
  • Negative (Negative form)
type ใ„ใ„ = IAdjective & { stem: "ใ„"; ending: "ใ„"; irregular: true };
type ็ถบ้บ— = NaAdjective & { stem: "็ถบ้บ—" };

๐Ÿ”— Copula System

The copula (ใ  / ใงใ™) turns a ไฝ“่จ€ (noun or na-adjective stem) into a statement โ€” "X is โ€ฆ". It is not a particle: like a verb or an adjective it inflects for politeness, tense and polarity, so it is modeled as a conjugable word via ConjugateCopula<Taigen, Form> (mirroring ConjugateVerb / ConjugateAdjective).

Copula Conjugation Forms

  • Plain โ†’ ใ  (plain) ใƒป Polite โ†’ ใงใ™ (polite)
  • Past โ†’ ใ ใฃใŸ ใƒป PolitePast โ†’ ใงใ—ใŸ
  • Negative โ†’ ใงใฏใชใ„ ใƒป PoliteNegative โ†’ ใงใฏใ‚ใ‚Šใพใ›ใ‚“
  • NegativePast โ†’ ใงใฏใชใ‹ใฃใŸ ใƒป PoliteNegativePast โ†’ ใงใฏใ‚ใ‚Šใพใ›ใ‚“ใงใ—ใŸ
  • CasualNegative โ†’ ใ˜ใ‚ƒใชใ„ ใƒป CasualPoliteNegative โ†’ ใ˜ใ‚ƒใ‚ใ‚Šใพใ›ใ‚“
  • Written โ†’ ใงใ‚ใ‚‹๏ผˆformal written๏ผ‰ใƒป Te โ†’ ใง๏ผˆconnective๏ผ‰

The copula has no generic attributive form: ใช is licensed only for ใช-adjectives (้™ใ‹ใช็”บ), never for plain nouns (ร—ๅŒป่€…ใช โ€” a noun takes ใฎ), so it lives in the adjective system, not here.

type ๅŒป่€…ใ  = ConjugateCopula<"ๅŒป่€…", "Plain">; // ๅŒป่€…ใ 
type ๅŒป่€…ใงใฏใ‚ใ‚Šใพใ›ใ‚“ = ConjugateCopula<"ๅŒป่€…", "PoliteNegative">; // ๅŒป่€…ใงใฏใ‚ใ‚Šใพใ›ใ‚“

๐Ÿ“š Phrase and Sentence Composition

The system now supports:

  • Adjectives and verbs with particles
  • Connecting phrases with Korean punctuation
  • Basic sentence structures
  • Conditional expressions with particles like ใชใ‚‰
  • Demonstrative forms with actions

Example: Connecting simple adjective and imperative verb phrases

// I-adjective "ii" (good) with irregular conjugation
// Then add particle "yo" to basic form of "ii" -> "ii yo"
type ใ„ใ„ = IAdjective & { stem: "ใ„"; ending: "ใ„"; irregular: true };
type ใ„ใ„ใ‚ˆ = PhraseWithParticle<ConjugateAdjective<ใ„ใ„, "Basic">, "ใ‚ˆ">;

// Irregular verb "kuru" (to come)
// Then add particle "yo" to imperative form of "kuru" -> "koi yo"
type ๆฅใ‚‹ = IrregularVerb & { dictionary: "ๆฅใ‚‹" };
type ๆฅใ„ใ‚ˆ = PhraseWithParticle<ConjugateVerb<ๆฅใ‚‹, "Imperative">, "ใ‚ˆ">;

// Connect both phrases -> "ii yo, koi yo"
type ใ„ใ„ใ‚ˆๆฅใ„ใ‚ˆ = ConnectedPhrases<ใ„ใ„ใ‚ˆ, ๆฅใ„ใ‚ˆ>;

// Type checking examples
const correctPhrase1: ใ„ใ„ใ‚ˆ = "ใ„ใ„ใ‚ˆ"; // "It's good!" (114)
const correctPhrase2: ๆฅใ„ใ‚ˆ = "ๆฅใ„ใ‚ˆ"; // "Come here!" (514)
const correctFullPhrase: ใ„ใ„ใ‚ˆๆฅใ„ใ‚ˆ = "ใ„ใ„ใ‚ˆใ€ๆฅใ„ใ‚ˆ"; // "It's good, come here!"

Example: More flexible component-based sentence construction

type SentenceParts = [
  AdverbPart<"ใชใ‚“ใง">, // "Why" - question adverb
  IntensifierPart<"ใใ‚“ใชใซ">, // "So much" - intensifier
  VerbPart<ๆ…ฃใ‚Œใ‚‹, "Te">, // "Get used to" in te-form
  ContractedPart<"ใ‚“">, // Contraction of "ใฎ" - colloquial nominalizer
  CopulaPart<"Plain">, // Copula "is" (ใ ) โ€” a conjugable copula, not a particle
  ParticlePart<"ใ‚ˆ"> // Emphatic sentence-ending particle
];

// Combines all parts into a single string
type JoinedSentence = JoinPhrasePartsValue<SentenceParts>;
const joinedSentence: JoinedSentence = "ใชใ‚“ใงใใ‚“ใชใซๆ…ฃใ‚Œใฆใ‚“ใ ใ‚ˆ"; // "Why are you so used to it?!"
// ไฝ ไธบไป€ไนˆ่ฟ™ไนˆ็†Ÿ็ปƒๅ•Š๏ผŸ

โš™๏ธ Technical Implementation

The system uses TypeScript's template literal types, conditional types, and mapped types to create a purely type-level representation of Korean grammatical rules.

Key components:

  • Type definitions for grammatical elements
  • Rule mapping via conditional types
  • String literal manipulation for form generation
  • Type inference for grammatical validation

๐Ÿ’ก Why Typed Korean?

  • Educational tool - Learn Korean grammar through code
  • AI-assisted learning - Provide structured formats for language analysis
  • Grammar verification - Express and verify Korean grammar in code
  • Integration potential - Basis for typed Korean language tools

โš ๏ธ Limitations

  • This is a type-level system only - it doesn't provide runtime functionality
  • The system handles standard forms but doesn't account for linguistic nuances
  • Some rare or archaic language patterns may not be accurately represented

This project is still in very early stages and heavily relies on LLM-generated grammar rules, which may occasionally contain hallucinations or inaccuracies. If you find any issue during actual use, please help by confirming and providing feedback.

๐Ÿ› ๏ธ Development

If you're interested in contributing to or experimenting with Typed Korean:

  1. Ensure you have Node.js and pnpm installed
  2. Clone the repository
  3. Install dependencies: pnpm install
  4. Run the tests: pnpm test

The tests validate that the type system functions correctly and all grammatical rules are properly implemented.

We welcome contributions! Feel free to open issues for bugs or feature requests, or submit pull requests with improvements.

๐Ÿ“ฌ Contact

For sponsorship opportunities, research collaborations, or commercial inquiries, please reach out to contact@typedgrammar.com.

โš–๏ธ License

MIT

Copyright (c) 2025-present, Yifeng Wang

About

๐Ÿ‡ฐ๐Ÿ‡ท Learn Korean grammar with TypeScript

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages