DEV Community

puffball1567
puffball1567

Posted on

Kinmokusei v0.2.0: Generic OOP and Go Type Constraints for a TypeScript-Inspired Language

Kinmokusei v0.2.0 expands the language in the places where application code and the Go ecosystem meet: generic object-oriented programming, generic constraints, type aliases, and JSON interop. Kinmokusei uses TypeScript-inspired syntax, but compiles to readable Go and uses the ordinary Go toolchain and package ecosystem directly. This release makes several of those boundaries more capable without treating generated Go as an opaque implementation detail.

Generic class inheritance and virtual dispatch

Classes in Kinmokusei are reference types. v0.2.0 adds generic class static methods, generic class inheritance, and generic virtual dispatch. A generic derived class can inherit a base class with concrete or remapped type arguments, retain the inherited state, and override a virtual member while preserving the expected dispatch behavior through the hierarchy.

That matters when a reusable abstraction carries its data type through more than one layer. A paged result, a domain-specific collection, or a typed application model should not need to discard its type parameter merely because it adds behavior in a derived class.

The release also adds descendant-aware class downcasts. A checked downcast can recover a more specific type within the same class hierarchy while keeping the failure path explicit, rather than silently assuming that every base-class value has the desired derived shape.

const [guide, ok] = animal as? GuideDog;
if (ok) {
  console(guide.speak());
}
Enter fullscreen mode Exit fullscreen mode

The checked form returns a value together with a boolean result. It makes the runtime boundary visible at the call site, while reference identity and virtual dispatch remain part of the class model.

Use Go type-set constraints from Kinmokusei

Go libraries increasingly express generic capabilities through interface type sets. v0.2.0 lets Kinmokusei use exported constraints from the Go standard library and external Go modules, rather than limiting generic code to comparable.

For example, code can use a constraint such as cmp.Ordered when an operation really requires an ordered value:

import go cmp from "cmp";

function earlier<T extends cmp.Ordered>(left: T, right: T): boolean {
  return left < right;
}
Enter fullscreen mode Exit fullscreen mode

This is useful because it keeps the constraint owned by the Go package that defines it. Kinmokusei code can participate in the same generic API shapes as Go code, instead of recreating a parallel constraint vocabulary.

Generic aliases without raising the minimum Go version

v0.2.0 also adds transparent generic aliases. An alias can give a reusable Kinmokusei name to a parameterized shape without introducing a new nominal type:

alias Values<T> = T[];
alias Lookup<K, V> = Map<K, V>;
Enter fullscreen mode Exit fullscreen mode

The compiler expands a generic alias to its instantiated underlying type at generated-Go boundaries. That detail is important for compatibility: the emitted code remains usable with the project's Go 1.23 minimum instead of depending on later Go generic-alias declarations. Kinmokusei tooling still retains the source-level alias, while Go consumers see the concrete Go type they expect.

v0.2.0 also permits a native struct as the underlying representation of a distinct type. This gives application code a way to add nominal meaning to an existing value layout while keeping conversions explicit and retaining Go-compatible value behavior.

Stable JSON behavior for generic and inherited classes

JSON is often the point where a type system meets an external API, stored data, or a frontend. v0.2.0 stabilizes JSON interop for generic classes: public fields use stable Kinmokusei field names, inherited public state is included, and private or protected state is excluded.

Decoding into a class instance preserves the class's reference-oriented model. Constructor-created instances retain their identity and virtual dispatch behavior, rather than being reduced to an unstructured map at the application boundary. Where a wire format needs special initialization or a different representation, an application can still define its own JSON handling.

A release focused on typed boundaries

These features are connected by the same goal: carry useful type information across the boundaries that real Go applications need to cross. Generic classes can model reusable reference-oriented behavior, Go type sets make interop constraints available directly, generic aliases keep source code readable without increasing the Go version requirement, and stable JSON rules make external data handling predictable.

Kinmokusei v0.2.0 is available now. Developers with Go installed can try the release with:

go install github.com/puffball1567/kinmokusei/cmd/keika@v0.2.0
keika version
Enter fullscreen mode Exit fullscreen mode

The compiler supports Go 1.23 through Go 1.27. The release notes, source, and executable examples are available in the Kinmokusei repository.

Top comments (0)