close

Filter

loading table of contents...

CoreMedia Content Cloud v11 Upgrade Guide / Version 2110

Table Of Contents

7.3.1.1 Basics

  • public is the default in TypeScript, so all public modifiers are gone

  • Class members do not use function, var or const keywords in TypeScript. Methods use parenthesis, const becomes readonly.

  • The constructor is not named like the class, but uses the well-known name constructor. No return type is specified.

  • This built-in ActionScript classes String, Number, Boolean are usually used in the "unboxed", lower-case variants string, number, boolean in TypeScript.

  • this must always be used explicitly (like in JavaScript)

  • private is available in TypeScript, but only affects the compiler. To be private for subclasses and at runtime, there is a new JavaScript syntax: Using a member name that starts with # makes it private.

  • A set accessor may not specify a void return value in TypeScript.

  • The ActionScript "untyped type"*maps to TypeScript'sany.

  • In ActionScript, parameter default values are only applied if the function/method is called without an argument for that parameter. In TypeScript, parameter default values are also applied if the function/method is called with a given argument that is undefined. This is a subtle difference and only rarely results in different semantics, but note that the conversion tool does not take care of these rare cases, so they can lead to undesired behavior and must be fixed manually.

  • While in ActionScript, typed class fields are implicitly assigned a default value (for example, 0 for an int), in TypeScript, all default values must be given explicitly. Otherwise, the field would remain undefined.

  • ActionScript classes may contain "top-level" code, optionally enclosed in curly braces, which is executed when the class is first loaded / used. In TypeScript, such code is put in a block prefixed by the static keyword.

ActionScript TypeScript
public class Foo extends SuperFoo {
  public static const FOO: * = "FOO";
  public var foo: String;
  private var _bar: Number;

  public function Foo(newBar: Number) {
    super();
    _bar = newBar;
  }

  public function get bar(): Number {
    return _bar;
  }

  public function set bar(value: Number): void {
    _bar = value;
  }

  protected function hook(): Boolean {
    return false;
  }

  Registry.register(Foo);
}
class Foo extends SuperFoo {
  static readonly FOO: any = "FOO";
  foo: string = null;
  #bar: number;

  constructor(newBar: number) {
    super();
    this.#bar = newBar;
  }

  get bar(): number {
    return this.#bar;
  }

  set bar(value: number) {
    this.#bar = value;
  }

  protected hook(): boolean {
    return false;
  }

  static { Registry.register(Foo); }

}

Table 7.1.  Basic ActionScript-TypeScript example comparison


Search Results

Table Of Contents
warning

Your Internet Explorer is no longer supported.

Please use Mozilla Firefox, Google Chrome, or Microsoft Edge.