Skip to content

Commit

Permalink
Bug fix for non-generic dictionaries and json objects
Browse files Browse the repository at this point in the history
  • Loading branch information
Caelan Sayler committed Nov 10, 2017
1 parent 2ff46da commit 7a1760e
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>netstandard1.6;net452;net461</TargetFrameworks>
<TargetFrameworks>netstandard1.6;net452</TargetFrameworks>
</PropertyGroup>

<ItemGroup>
Expand Down
10 changes: 10 additions & 0 deletions TypeGap/TypeConverter.cs
Expand Up @@ -88,9 +88,19 @@ public string GetTypeScriptName(Type clrType)
return result;
}

// these objects generally just mean json, so 'any' is appropriate.
if (clrType.Namespace == "Newtonsoft.Json.Linq")
{
return "any";
}

// Dictionaries -- these should come before IEnumerables, because they also implement IEnumerable
if (clrType.IsIDictionary())
{
if (clrType.GenericTypeArguments.Length != 2)
return "{ [key: string]: any }";

// TODO: can we use Map<> instead? this will break if the first argument is not string | number.
return $"{{ [key: {GetTypeScriptName(clrType.GetDnxCompatible().GetGenericArguments()[0])}]: {GetTypeScriptName(clrType.GetDnxCompatible().GetGenericArguments()[1])} }}";
}

Expand Down
2 changes: 1 addition & 1 deletion TypeGap/TypeGap.csproj
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>netstandard1.6;net452;net461</TargetFrameworks>
<TargetFrameworks>netstandard1.6;net452</TargetFrameworks>
</PropertyGroup>

<ItemGroup Condition=" '$(TargetFramework)' != 'netstandard1.6' ">
Expand Down

0 comments on commit 7a1760e

Please sign in to comment.