Skip to content

CoffeeScript To TypeScript Features

Erik Demaine edited this page Jan 23, 2022 · 32 revisions

This is a running list of supported and not-yet-supported features on my typescript branch. See this wiki page for another list of TypeScript features.

Types

  • Primitive types given by any identifier: any, unknown, object, void, never, number, string, boolean, bigint, symbol, Function
  • Literal types: numbers, strings, booleans, and within typeof, Infinity, NaN
  • null, undefined, and void types
  • Function types: (arg1 ~ ArgType, arg2 ~ ArgType) -> returnType (or ditto with =>)
    • Optional parameters: (arg? ~ ArgType) ~ ReturnType -> ...
  • Constructor type: new ...
  • Array types: baseType[]
  • Tuple types: [name ~ string, age ~ number]
  • Object types, including optional properties: {key: string, value?: number} or omitting braces as usual in CoffeeScript:
    key: string
    value?: number
    • [keyExpr]: value
  • Union types: type1 | type2
  • Intersection types: type1 & type2
  • keyof, unique, readonly operators
  • Type indexing: T["key"]
  • Namespace dereferencing: space.T
  • Mapped types: {[Key in keyof Type]: ...}
  • typeof operator
  • Template types, e.g. ReturnType<T>, Partial<T>, Required<T>, Readonly<T>, Record<K,T>, Pick<T,K>, Omit<T,K>, Iterable<T>, ...
  • Conditional types: if { legs: 4 } then Animal else never
  • Template string types: "index.#{"en" | "fr"}.html"
  • extends assertion: T extends S
  • TypeScript passthrough: `passthrough code`

Type Annotation

  • ~ or := assigning type to a variable: variable ~ Type
  • Assigning to variable as it's typed: variable ~ Type = value
    • After-indented-type next-line assignment:
      variable ~
        key: string
        value?: number
      =
        key: 'hello'
        value: 7
  • Function typing (arg1 ~ ArgType, arg2 ~ ArgType) ~ ReturnType -> ...
    • Optional parameters: (arg? ~ ArgType) ~ ReturnType -> ...
  • Generic functions: f = <T>(a ~ T[]) ~ T -> a[0]
  • Function overloads?
  • Class attributes via x ~ T
  • Generic classes: class Box<T>
  • class ... implements ...
  • Type guards: (obj) ~ obj is Response -> (conflict with CoffeeScript is?)
  • Type assertions: (obj) ~ asserts obj is Response

Type Definitions

  • type
    • Leading | in multiline unions
    • Template types: type Foo<T>
    • extends
  • interface
    • Template interfaces: interface Foo<T>
    • extends
  • import type
  • declare
  • module
  • namespace

Type Casting

  • Nonnull assertion: !
  • as
  • as const

Nontype features

  • private, protected, public, readonly variable modifiers
  • enum
  • #@tsc-ignore
  • #/ <directive />
Clone this wiki locally