Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: microsoft/TypeScript
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: main
Choose a base ref
...
head repository: rkirov/TypeScript
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: master
Choose a head ref
Checking mergeability… Don’t worry, you can still create the pull request.
  • 9 commits
  • 17 files changed
  • 2 contributors

Commits on Mar 15, 2026

  1. Add higher-kinded types (HKTs) — v0 proof of concept

    Introduce first-class support for abstracting over type constructors via
    kind annotations in type parameter syntax: `<F : * -> *>`.
    
    This enables writing generic abstractions like Functor and Monad that
    work across Array, Promise, user-defined types, and any type constructor
    of the right kind — eliminating the need for defunctionalization hacks.
    
    What works:
    - Kind annotation syntax parsed from `<F : * -> *>` (no new tokens)
    - `Functor<Array>`, `Monad<Box>` — concrete and user-defined constructors
    - `F<A>` type application resolves to `Array<A>` when F = Array
    - Monad<F> extends Functor<F> — HKT params forwarded through inheritance
    - Generic functions: lift, when, sequence all typecheck
    - Type inference: `boxMonad.pure(42)` infers `Box<number>`
    - Invariant assignability for abstract constructor applications
    - Arity checking: `F<A, B>` errors when `F : * -> *`
    - Full backward compatibility with existing TypeScript code
    - 12 test cases passing in the standard test suite
    
    Compiler changes:
    - parser.ts: parseKindAnnotation() for `* -> *` syntax
    - types.ts: kindArity on TypeParameterDeclaration and TypeParameter;
      hktConstructorSymbol and hktTypeArguments on Type
    - checker.ts: TypeConstructorRef and HKTApplicationType representations
      (both piggyback on TypeFlags.Substitution); HKT-aware type argument
      resolution, instantiation, assignability, and inference
    
    Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
    rkirov and claude committed Mar 15, 2026
    Configuration menu
    Copy the full SHA
    960dc97 View commit details
    Browse the repository at this point in the history
  2. Add HKT playground — interactive browser demo

    Self-contained HTML page that loads the custom TypeScript compiler and
    provides a live type-checking editor with example buttons for Functor,
    Monad, Sequence, and error cases.
    
    Serve from repo root: python3 -m http.server 8080
    Open: http://localhost:8080/hkt-playground.html
    
    Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
    rkirov and claude committed Mar 15, 2026
    Configuration menu
    Copy the full SHA
    a643e6e View commit details
    Browse the repository at this point in the history
  3. Upgrade HKT playground to Monaco editor

    Replace textarea with Monaco editor for full IDE experience: syntax
    highlighting, bracket matching, error squigglies, line numbers, and
    click-to-navigate on diagnostic locations.
    
    Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
    rkirov and claude committed Mar 15, 2026
    Configuration menu
    Copy the full SHA
    35960b6 View commit details
    Browse the repository at this point in the history
  4. Add custom hover provider using HKT-aware compiler

    Replace Monaco's built-in TypeScript hover (which shows `any` for HKT
    types) with a custom hover provider that queries our compiler's type
    checker. Hovering over `fa: F<A>` now shows the correct type from our
    HKT-aware checker, and type parameters with kind annotations display
    their kind (e.g., `F : * -> *`).
    
    Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
    rkirov and claude committed Mar 15, 2026
    Configuration menu
    Copy the full SHA
    1160d44 View commit details
    Browse the repository at this point in the history
  5. Change kind syntax to uncurried form with tuple parameters

    Replace Haskell-style curried kind arrows with explicit tuple syntax:
    - `* -> *` for one-arg constructors (unchanged)
    - `(*, *) -> *` for two-arg constructors (was `* -> * -> *`)
    - `(*) -> *` is sugar for `* -> *`
    - `(* -> *) -> *` parses but errors: "Higher-order kinds are not yet
      supported"
    
    The parser now handles a full kind grammar with parens, commas, and
    right-associative arrows. Internally, a KindNode tree is stored on
    the AST alongside the simple kindArity count. The checker validates
    that all kind parameters and return are `*`, rejecting higher-order
    kinds with a clear diagnostic (TS2900).
    
    Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
    rkirov and claude committed Mar 15, 2026
    Configuration menu
    Copy the full SHA
    7b1cbbf View commit details
    Browse the repository at this point in the history
  6. Support higher-order kinds: (* -> *) -> * and beyond

    Remove the "not yet supported" restriction on higher-order kinds.
    Type constructors can now take other type constructors as parameters:
    
      type ApplyToArray<F : (* -> *) -> *> = F<Array>
      interface Wrapper<F : * -> *> { wrap<A>(a: A): F<A> }
    
    Changes:
    - Store full KindNode tree on TypeParameter (alongside kindArity)
    - Add kind utilities: kindsMatch(), getKindOfType(), getKindOfSymbol(),
      kindToString() for recursive kind comparison
    - resolveTypeConstructorArgument now uses full kind matching instead
      of simple arity equality
    - isHKTTypeArgumentContext handles TypeParameter parents (F<Array>
      where F is itself a higher-kinded parameter)
    - Force-resolve type alias symbols in isHKTTypeArgumentContext to
      ensure typeParameters are populated
    
    Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
    rkirov and claude committed Mar 15, 2026
    Configuration menu
    Copy the full SHA
    e374e0d View commit details
    Browse the repository at this point in the history
  7. Update HKT.md with higher-order kinds and new syntax

    Reflect current state: uncurried kind syntax, higher-order kinds
    supported, 18 tests passing, live demo link.
    
    Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
    rkirov and claude committed Mar 15, 2026
    Configuration menu
    Copy the full SHA
    dfc8c82 View commit details
    Browse the repository at this point in the history
  8. Add Bifunctor and Higher-Order examples to playground

    New example tabs showing (*, *) -> * with Pair/Bifunctor and
    (* -> *) -> * with ApplyToNumber, NaturalTransformation, and
    nested kind aliases.
    
    Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
    rkirov and claude committed Mar 15, 2026
    Configuration menu
    Copy the full SHA
    53f29b3 View commit details
    Browse the repository at this point in the history
  9. Improve Higher-Order example with Nat composition

    Show natural transformations (Nat<F, G> where F, G : * -> *) and
    composition of natural transformations (composeNat with three * -> *
    params), demonstrating genuine higher-kinded programming.
    
    Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
    rkirov and claude committed Mar 15, 2026
    Configuration menu
    Copy the full SHA
    b4782dd View commit details
    Browse the repository at this point in the history
Loading