Skip to content
Aurélio A. Heckert edited this page May 3, 2020 · 15 revisions

This is a living document to assemble product requirements for potential TypeScript output from the CoffeeScript compiler.

If the CoffeeScript compiler were to output TypeScript source code, similar to the way it outputs JSX now, what TypeScript syntax should it support?

It’s a separate question what CoffeeScript syntax will be designed to support each TypeScript syntax; for now we just want to create a list of output syntax that we eventually want to support.

function greeter(person: string) {}

class Student {
  fullName: string;
  constructor(public firstName: string, public middleInitial: string, public lastName: string) {}
}

let list: Array<number> = [1, 2, 3];
interface Person {
  firstName: string;
  lastName: string;
}
type WindowStates = "open" | "closed" | "minimized";
type BotId = string | number
function buildName(firstName: string, lastName?: string) {
  if (lastName) return firstName + " " + lastName;
  else return firstName;
}
class Animal {
  private id: string;
  protected name: string;
  public constructor(theName: string) {
    this.name = theName;
  }
  public move(distanceInMeters: number) {
    console.log(`${this.name} moved ${distanceInMeters}m.`);
  }
}
class Octopus {
  readonly name: string;
  readonly numberOfLegs: number = 8;
  constructor(theName: string) {
    this.name = theName;
  }
}

Accessors (ES6)

class Employee {
  private _fullName: string;

  get fullName(): string {
    return this._fullName;
  }

  set fullName(newName: string) {
    if (newName && newName.length > fullNameMaxLength) {
      throw new Error("fullName has a max length of " + fullNameMaxLength);
    }
    this._fullName = newName;
  }
}
abstract class Animal {
  abstract makeSound(): void;
  move(): void {
    console.log("roaming the earth...");
  }
}

class Cat extends Animal {
  constructor() {
    super("I'm a cat"); // constructors in derived classes must call super()
  }
  makeSound(): void {
    console.log('Meowwww')
  }
}
declare global {
  interface Array<T> {
    toObservable(): Observable<T>;
  }
}

Array.prototype.toObservable = function() {
  ...
};