Skip to content

ValueTuple support with TypeFunctions.ToTypeScriptType #63

@Prinsn

Description

@Prinsn

for the class

public foo {
  public (int, string) easy {get;set}
  public IEnumerable<(int, string)> hard {get;set}
}

which will emit for types using ToTypeScriptType

easy: <number, string>;
hard: <number, string>[];

I know this is kind of a weird case because I don't know that there is a type for ValueTuple to map to, and we got around this by supplying our own type(s)

export interface ValueTuple<TOne, TTwo> {
    item1: TOne,
    item2: TTwo
}

The easy case is solved easy enough with custom script

public static string ToTypeScriptType(IType type, IClass c)
{
  var prefix = type.Name.StartsWith("(") ? "ValueTuple" : "";
  return prefix + TypeFunctions.ToTypeScriptType(type);
 }

But trying to solve it generically for any instance of a value tuple seems to require custom rewrite of ToTypeScriptType to make use of this.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions