Skip to content
Converts TypeScript code to General Language Syntax (GLS).
TypeScript JavaScript
Branch: master
Clone or download
JoshuaKGoldberg Merge pull request #70 from general-language-syntax/greenkeeper/@type…

Update @types/node to the latest version 🚀
Latest commit 641c1d6 May 4, 2019
Type Name Latest commit message Commit time
Failed to load latest commit information.
tslint.json Added tslint-config-prettier Sep 1, 2018

TS-GLS - TypeScript to GLS compiler

Build Status NPM version Greenkeeper badge

Compiles TypeScript code to General Language Syntax (GLS).

GLS is an abstract way to describe lines of code in real languages. TypeScript is a gradually typed language, so a subset of well-typed TS code can generally be converted to GLS.


It's impossible to accurately convert TS code to GLS. Although large constructs such as classes and interfaces can be, there are edge cases around primitive literals not representable in TypeScript.

For example, TS-GLS has no way of knowing whether age: number is a GLS float or int:

export class AgePrinter {
    public printAge(name: string, age: number): void {
        console.log(`${name} is ${age} year(s) old.`);

The TS string type also can't be statically determined to be a GLS char or string.

Thus, TS-GLS will never be more than an experiment. Only a completely strongly typed language with ints and chars, such as C# or Java, can truly be compiled to GLS. TS-GLS can only get code most of the way there.


You can use TS-GLS on the command-line with gls-cli or in code.


gls --language Java --tsconfig ./tsconfig *.ts

See gls-cli


createTransformer creates a Transformer object that can transform source files to GLS. It requires all files at construction so it can create a TypeScript program.

import * as ts from "typescript";
import { createTransformer } from "ts-gls";

const sourceFile = ts.createSourceFile("_.ts", "let x = true;", ScriptTarget.Latest);
const transformer = createTransformer({
    sourceFiles: [sourceFile],

// ["variable : x boolean true"]


To build from scratch, install Node.js and run the following commands:

npm install
npm install general-language-syntax --no-save
npm run verify

Check package.json for the full list of commands. To set up source file compiling in watch mode, use tsc -p . -w.


Integration and end-to-end tests are done using BDD. Folders under /test/integration and /test/end-to-end will contain a .ts file with TypeScript source code along with an equivalent .gls file with the expected GLS compilation result. These are verified during npm run test test.

You can run specific tests using their run task (npm run test:run:integration or npm run test:run:end-to-end). Specify --command(s) to only run tests within groups that case-insensitive minimatch them (e.g. npm run test:run:end-to-end -- --command *array* *list*).

You can’t perform that action at this time.