Sign Up for Free

RunKit +

Try any Node.js package right in your browser

This is a playground to test code. It runs a full Node.js environment and already has all of npm’s 400,000 packages pre-installed, including @kogai/typed_i18n with all npm packages installed. Try it out:

var typedI18n = require("@kogai/typed_i18n")

This service is provided by RunKit and is not affiliated with npm, Inc or the package authors.

@kogai/typed_i18n v0.6.0

Type safe i18n with Flow and TypeScript


npm version CircleCI

Generate strictly typed definition of TFunction from own i18next dictionary file.

It generate from

  "en": {
    "translation": {
      "foo": {
        "bar": "some text",
        "buzz": 999


// @flow
declare function t(_: "foo"): {
  +bar: string,
  +buzz: number
declare function t(_: ""): string;
declare function t(_: ""): number;

export type TFunction = typeof t;


declare namespace typed_i18n {
  interface TFunction {
    t(_: "foo"): {
      +bar: string,
      +buzz: number,
    t(_: ""): string;
    t(_: ""): number;
export = typed_i18n;

then if you use TFunction like below, type-checker warn you function call by invalid path

// @flow

import type { TFunction } from "./locale.translation"; // Definition file generated

declare var t: TFunction;

// Those are ok
const x: { bar: string, buzz: number } = t("foo");
const x1: string =;
const x2: number =;
// Expect error
const x3 = x.buzzz;

// Expect error
const y = t("fooo");

// Those are also strictly typed too
const z1: string = t("");
const z2: number = t("");


# Basic usage
$ typed_i18n -i path/to/your.json -o path/to/out/dir

# Support also typescript
$ typed_i18n -i path/to/your.json -o path/to/out/dir -l typescript

# You can specify namespaces instead of default "translation"
$ typed_i18n -i path/to/your.json -o path/to/out/dir -n translate -n my-namespace -n other-namespace
RunKit is a free, in-browser JavaScript dev environment for prototyping Node.js code, with every npm package installed. Sign up to share your code.
Sign Up for Free