Nice.

I personally like explicit types because it’s more human readable.

How feasable would it be to automatically add types to the code based on type 
inference. So var s = “hello” could be transformed to var s:String = “hello”.

Do you need to assign the variable when it’s declared for this to work?

> On Jun 21, 2023, at 12:07 AM, Josh Tynjala <joshtynj...@bowlerhat.dev> wrote:
> 
> Hi all,
> 
> One cool feature in other languages similar to AS3, such as TypeScript or
> Haxe, is type inference. It allows developers to optionally omit a type
> declaration from a variable, or a function signature, by having the
> compiler automatically detect an appropriate type from context.
> 
> For example, you traditionally would declare a variable with a String type
> like this:
> 
> var s:String = "hello";
> 
> If you enable type inference, you can declare the same variable like this
> instead because the compiler knows that the initializer is a string.
> 
> var s = "hello";
> 
> Type inference applies to local/member/static variables, getters/setters,
> function parameters, and function return values. If a function has multiple
> return statements, the type inference will try to find a common base type,
> if possible. If a type cannot be inferred for any reason, the compiler will
> fall back to the * type, and you'll get a warning, the same as when type
> inference is disabled.
> 
> If you build the compiler from source (or download the next nightly build),
> you can enable this feature in your project using the new -infer-types=true
> compiler option. It is opt-in for now, to avoid any potential backwards
> compatibility issues with existing code.
> 
> I also wrote some documentation with examples and more detailed
> explanations:
> 
> https://apache.github.io/royale-docs/features/as3/type-inference
> 
> --
> Josh Tynjala
> Bowler Hat LLC <https://bowlerhat.dev>

Reply via email to