Thank you Josh!!! This is probably my #1 feature I’ve been missing in ActionScript.
This will do a world of good for type safety and being able to express required types! I’m looking forward to making use of this! Harbs > On Jan 20, 2026, at 10:29 PM, Josh Tynjala <[email protected]> wrote: > > Hi folks, > > I just wanted to take a moment to highlight a new ActionScript language > feature that I recently implemented in Royale's compiler: Function type > expressions. Or perhaps you might call them strict function types. > > Basically, instead of using the Function type, like this: > > var validate:Function; > > You can define the function signature as a type, like this (The syntax is > pretty similar to TypeScript's): > > var validate:(input:String)=>Boolean; > > And then, the compiler can check for mismatches. The following assignment > will fail: > > var validate:(input:String)=>Boolean = function(input:ByteArray):Boolean { > return false; } > > It should give the following error: > > Error: Implicit coercion of a value of type (input:ByteArray)=>Boolean to > an unrelated type (input:String)=>Boolean. > > The syntax supports optional parameters and rest parameters. Optional > parameters would be equivalent to parameters that have a default value in a > regular function signature. However, you don't need to specify the default > value in the function type expression (assigned functions are allowed to > have different default values or to use rest instead), and you may use the > ? token to indicate that a specific parameter is optional. > > var func:(s?:String, ...rest):void; > > You can even nest function type expressions. > > var action:(callback:(result:Object)=>void):void; > > I've created some documentation to help folks get started: > > https://apache.github.io/royale-docs/features/as3/strict-function-types > > -- > Josh Tynjala > Bowler Hat LLC > https://bowlerhat.dev/
