CoreMedia Content Cloud v11 Upgrade Guide / Version 2110
Table Of Contentspublic
is the default in TypeScript, so allpublic
modifiers are goneClass members do not use
function
,var
orconst
keywords in TypeScript. Methods use parenthesis,const
becomesreadonly
.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 variantsstring
,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 avoid
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 anint
), in TypeScript, all default values must be given explicitly. Otherwise, the field would remainundefined
.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