Implicit/explicit cast operators

Topics: General
Sep 26, 2013 at 4:49 PM
Is it possible to implement implicit or explicit cast in TypeScript ?
Like in C#:
class ToAnything
{
    public static int operator implicit(ToAnything x) { return 1; }
}
If yes, is it possible to define generic cast operators ?
For instance you can do in Nemerle language:
class ToAnything
{
  public static @:[T](_ : this) : T { default(T); }
}
C# (pseudo code, cause it is impossible):
class ToAnything
{
    public static T operator implicit<T>(ToAnything x) { return default(T); }
}
And then instance of this class can be converted to any type.
Developer
Sep 27, 2013 at 7:02 PM
No, TypeScript doesn't support anything like this at present.