Comparing microsoft:main...rkirov:master · microsoft/TypeScript

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) <noreply@anthropic.com>

    and claude committed

    Mar 15, 2026
    Configuration menu

    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) <noreply@anthropic.com>
    Configuration menu

    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) <noreply@anthropic.com>
    Configuration menu

    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) <noreply@anthropic.com>
    Configuration menu

    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) <noreply@anthropic.com>
    Configuration menu

    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) <noreply@anthropic.com>
    Configuration menu

    Browse the repository at this point in the history

  7. Configuration menu

    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) <noreply@anthropic.com>
    Configuration menu

    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) <noreply@anthropic.com>
    Configuration menu

    Browse the repository at this point in the history