3

Closed

Implicit operators

description

In some classes configuration we often allow configure properties with multiple signatures:




new Ext.Panel({

tbar : new Ext.Toolbar({

items : [{text : 'save'}, {text : 'cancel'}]
})

}):




or




new Ext.Panel({

tbar : [{text : 'save'}, {text : 'cancel'}]

}):




It would be really nice if we had, only in compile time, a feature like C# implicit operator.

This pattern is used in scriptsharp.



http://msdn.microsoft.com/en-us/library/z5z9kes2(v=vs.100).aspx

http://extsharp.codeplex.com/SourceControl/changeset/view/94877#1716706

http://extsharp.codeplex.com/SourceControl/changeset/view/94877#1716724



so instead of declaring type any




class Panel {
public tbar: any;
}






we could create a class to inform what types we can convert




class Panel {
public tbar: TbarConfig;
}

class TbarConfig {
implicit operator Ext.Toolbar(items : any);
implicit operator Ext.Toolbar(items : Ext.Toobar);
}
Closed Jul 28 at 11:18 PM by jonturner
As part of our move to GitHub, we're closing our CodePlex suggestions and asking that people move them to the GitHub issue tracker for further discussion. Some feature requests may already be active on GitHub, so please make sure to look for an existing issue before filing a new one.

You can find our GitHub issue tracker here:
https://github.com/microsoft/typeScript/issues

comments