Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/IEvangelist/blazorators

This project converts TypeScript type declarations into C# representations, and use C# source generators to expose automatic JavaScript interop functionality.
https://github.com/IEvangelist/blazorators

blazor blazor-webassembly hacktoberfest javascript javascript-interop source-generators typescript

Last synced: about 2 months ago
JSON representation

This project converts TypeScript type declarations into C# representations, and use C# source generators to expose automatic JavaScript interop functionality.

Awesome Lists containing this project

README

        


# Blazorators: Blazor C# Source Generators

> Thank you for perusing my Blazor C# Source Generator repository. I'd really appreciate a ⭐ if you find this interesting.

[![build](https://github.com/IEvangelist/blazorators/actions/workflows/build-validation.yml/badge.svg)](https://github.com/IEvangelist/blazorators/actions/workflows/build-validation.yml)

[![All Contributors](https://img.shields.io/badge/all_contributors-11-orange.svg?style=flat-square)](#contributors-)

A C# source generator that creates fully functioning Blazor JavaScript interop code, targeting either the `IJSInProcessRuntime` or `IJSRuntime` types. This library provides several NuGet packages:

**Core libraries**

| NuGet package | NuGet version | Description |
|--|--|--|
| [`Blazor.SourceGenerators`](https://www.nuget.org/packages/Blazor.SourceGenerators) | [![NuGet](https://img.shields.io/nuget/v/Blazor.SourceGenerators.svg?style=flat)](https://www.nuget.org/packages/Blazor.SourceGenerators) | Core source generator library. |
| [`Blazor.Serialization`](https://www.nuget.org/packages/Blazor.Serialization) | [![NuGet](https://img.shields.io/nuget/v/Blazor.Serialization.svg?style=flat)](https://www.nuget.org/packages/Blazor.Serialization) | Common serialization library, required in some scenarios when using generics. |

**WebAssembly libraries**

| NuGet package | NuGet version | Description |
|--|--|--|
| [`Blazor.LocalStorage.WebAssembly`](https://www.nuget.org/packages/Blazor.LocalStorage.WebAssembly) | [![NuGet](https://img.shields.io/nuget/v/Blazor.LocalStorage.WebAssembly.svg?style=flat)](https://www.nuget.org/packages/Blazor.LocalStorage.WebAssembly) | Blazor WebAssembly class library exposing DI-ready `IStorageService` type for the `localStorage` implementation (relies on `IJSInProcessRuntime`). |
| [`Blazor.SessionStorage.WebAssembly`](https://www.nuget.org/packages/Blazor.SessionStorage.WebAssembly) | [![NuGet](https://img.shields.io/nuget/v/Blazor.SessionStorage.WebAssembly.svg?style=flat)](https://www.nuget.org/packages/Blazor.SessionStorage.WebAssembly) | Blazor WebAssembly class library exposing DI-ready `IStorageService` type for the `sessionStorage` implementation (relies on `IJSInProcessRuntime`). |
| [`Blazor.Geolocation.WebAssembly`](https://www.nuget.org/packages/Blazor.Geolocation.WebAssembly) | [![NuGet](https://img.shields.io/nuget/v/Blazor.Geolocation.WebAssembly.svg?style=flat)](https://www.nuget.org/packages/Blazor.Geolocation.WebAssembly) | Razor class library exposing DI-ready `IGeolocationService` type (and dependent callback types) for the `geolocation` implementation (relies on `IJSInProcessRuntime`). |
| [`Blazor.SpeechSynthesis.WebAssembly`](https://www.nuget.org/packages/Blazor.SpeechSynthesis.WebAssembly) | [![NuGet](https://img.shields.io/nuget/v/Blazor.SpeechSynthesis.WebAssembly.svg?style=flat)](https://www.nuget.org/packages/Blazor.SpeechSynthesis.WebAssembly) | Razor class library exposing DI-ready `ISpeechSynthesisService` type for the `speechSynthesis` implementation (relies on `IJSInProcessRuntime`). |

> Targets the `IJSInProcessRuntime` type.

**Server libraries**

| NuGet package | NuGet version | Description |
|--|--|--|
| [`Blazor.LocalStorage`](https://www.nuget.org/packages/Blazor.LocalStorage) | [![NuGet](https://img.shields.io/nuget/v/Blazor.LocalStorage.svg?style=flat)](https://www.nuget.org/packages/Blazor.LocalStorage) | Blazor Server class library exposing DI-ready `IStorageService` type for the `localStorage` implementation (relies on `IJSRuntime`) |
| [`Blazor.SessionStorage`](https://www.nuget.org/packages/Blazor.SessionStorage) | [![NuGet](https://img.shields.io/nuget/v/Blazor.SessionStorage.svg?style=flat)](https://www.nuget.org/packages/Blazor.SessionStorage) | Blazor Server class library exposing DI-ready `IStorageService` type for the `sessionStorage` implementation (relies on `IJSRuntime`) |
| [`Blazor.Geolocation`](https://www.nuget.org/packages/Blazor.Geolocation) | [![NuGet](https://img.shields.io/nuget/v/Blazor.Geolocation.svg?style=flat)](https://www.nuget.org/packages/Blazor.Geolocation) | Razor class library exposing DI-ready `IGeolocationService` type (and dependent callback types) for the `geolocation` implementation (relies on `IJSRuntime`). |
| [`Blazor.SpeechSynthesis`](https://www.nuget.org/packages/Blazor.SpeechSynthesis) | [![NuGet](https://img.shields.io/nuget/v/Blazor.SpeechSynthesis.svg?style=flat)](https://www.nuget.org/packages/Blazor.SpeechSynthesis) | Razor class library exposing DI-ready `ISpeechSynthesisService` type for the `speechSynthesis` implementation (relies on `IJSRuntime`). |

> Targets the `IJSRuntime` type.

> **Note**

> The reason that I generate two separate packages, one with an async API and another with the synchronous version is due to the explicit usage of `IJSInProcessRuntime` when using Blazor WebAssembly. This decision allows the APIs to be separate, and easily consumable from their repsective consuming Blazor apps, either Blazor server or Blazor WebAssembly. I might change it later to make this a consumer configuration, in that each consuming library will have to explicitly define a preprocessor directive to specify `IS_WEB_ASSEMBLY` defined.

## Using the `Blazor.SourceGenerators` package πŸ“¦

As an example, the official [`Blazor.LocalStorage.WebAssembly`](https://www.nuget.org/packages/Blazor.LocalStorage.WebAssembly) package consumes the [`Blazor.SourceGenerators`](https://www.nuget.org/packages/Blazor.SourceGenerators) package. It exposes extension methods specific to Blazor WebAssembly and the [`localStorage`](https://developer.mozilla.org/docs/Web/API/Window/localStorage) Web API.

Consider the _IStorageService.cs_ C# file:

```csharp
// Copyright (c) David Pine. All rights reserved.
// Licensed under the MIT License.

namespace Microsoft.JSInterop;

[JSAutoGenericInterop(
TypeName = "Storage",
Implementation = "window.localStorage",
Url = "https://developer.mozilla.org/docs/Web/API/Window/localStorage",
GenericMethodDescriptors = new[]
{
"getItem",
"setItem:value"
})]
public partial interface IStorageService
{
}
```

This code designates itself into the `Microsoft.JSInterop` namespace, making the source generated implementation available to anyone consumer who uses types from this namespace. It uses the `JSAutoGenericInterop` to specify:

- `TypeName = "Storage"`: sets the type to [`Storage`](https://developer.mozilla.org/docs/Web/API/Storage).
- `Implementation = "window.localStorage"`: expresses how to locate the implementation of the specified type from the globally scoped `window` object, this is the [`localStorage`](https://developer.mozilla.org/docs/Web/API/Window/localStorage) implementation.
- `Url`: sets the URL for the implementation.
- `GenericMethodDescriptors`: Defines the methods that should support generics as part of their source-generation. The `localStorage.getItem` is specified to return a generic `TResult` type, and the `localStorage.setItem` has its parameter with a name of `value` specified as a generic `TArg` type.

> The generic method descriptors syntax is:
> `"methodName"` for generic return type and `"methodName:parameterName"` for generic parameter type.

The file needs to define an interface and it needs to be `partial`, for example; `public partial interface`. Decorating the class with the `JSAutoInterop` (or `JSAutoGenericInterop) attribute will source generate the following C# code, as shown in the source generated _IStorageServiceService.g.cs_:

```csharp
using Blazor.Serialization.Extensions;
using System.Text.Json;

#nullable enable
namespace Microsoft.JSInterop;

///
/// Source generated interface definition of the Storage type.
///
public partial interface IStorageServiceService
{
///
/// Source generated implementation of window.localStorage.length.
///
///
double Length
{
get;
}

///
/// Source generated implementation of window.localStorage.clear.
///
///
void Clear();

///
/// Source generated implementation of window.localStorage.getItem.
///
///
TValue? GetItem(string key, JsonSerializerOptions? options = null);

///
/// Source generated implementation of window.localStorage.key.
///
///
string? Key(double index);

///
/// Source generated implementation of window.localStorage.removeItem.
///
///
void RemoveItem(string key);

///
/// Source generated implementation of window.localStorage.setItem.
///
///
void SetItem(string key, TValue value, JsonSerializerOptions? options = null);
}
```

These internal extension methods rely on the `IJSInProcessRuntime` to perform JavaScript interop. From the given `TypeName` and corresponding `Implementation`, the following code is also generated:

- `IStorageService.g.cs`: The interface for the corresponding `Storage` Web API surface area.
- `LocalStorgeService.g.cs`: The `internal` implementation of the `IStorageService` interface.
- `LocalStorageServiceCollectionExtensions.g.cs`: Extension methods to add the `IStorageService` service to the dependency injection `IServiceCollection`.

Here is the source generated `LocalStorageService` implementation:

```csharp
// Copyright (c) David Pine. All rights reserved.
// Licensed under the MIT License:
// https://github.com/IEvangelist/blazorators/blob/main/LICENSE
// Auto-generated by blazorators.

#nullable enable

using Blazor.Serialization.Extensions;
using Microsoft.JSInterop;
using System.Text.Json;

namespace Microsoft.JSInterop;

///
internal sealed class LocalStorageService : IStorageService
{
private readonly IJSInProcessRuntime _javaScript = null;

///
double IStorageService.Length => _javaScript.Invoke("eval", new object[1]
{
"window.localStorage.length"
});

public LocalStorageService(IJSInProcessRuntime javaScript)
{
_javaScript = javaScript;
}

///
void IStorageService.Clear()
{
_javaScript.InvokeVoid("window.localStorage.clear");
}

///
TValue? IStorageService.GetItem(string key, JsonSerializerOptions? options)
{
return _javaScript.Invoke("window.localStorage.getItem", new object[1]
{
key
}).FromJson(options);
}

///
string? IStorageService.Key(double index)
{
return _javaScript.Invoke("window.localStorage.key", new object[1]
{
index
});
}

///
void IStorageService.RemoveItem(string key)
{
_javaScript.InvokeVoid("window.localStorage.removeItem", key);
}

///
void IStorageService.SetItem(string key, TValue value, JsonSerializerOptions? options)
{
_javaScript.InvokeVoid("window.localStorage.setItem", key, value.ToJson(options));
}
}
```

Finally, here is the source generated service collection extension methods:

```csharp
using Microsoft.JSInterop;

namespace Microsoft.Extensions.DependencyInjection;

///
public static class LocalStorageServiceCollectionExtensions
{
///
/// Adds the service to the service collection.
///
public static IServiceCollection AddLocalStorageServices(
this IServiceCollection services) =>
services.AddSingleton(serviceProvider =>
(IJSInProcessRuntime)serviceProvider.GetRequiredService())
.AddSingleton();
}
```

Putting this all together, the `Blazor.LocalStorage.WebAssembly` NuGet package is actually less than 15 lines of code, and it generates full DI-ready services with JavaScript interop.

The `Blazor.LocalStorage` package, generates extensions on the `IJSRuntime` type.

```csharp
// Copyright (c) David Pine. All rights reserved.
// Licensed under the MIT License.

namespace Microsoft.JSInterop;

[JSAutoInterop(
TypeName = "Storage",
Implementation = "window.localStorage",
HostingModel = BlazorHostingModel.Server,
OnlyGeneratePureJS = true,
Url = "https://developer.mozilla.org/docs/Web/API/Window/localStorage")]
public partial interface IStorageServiceService
{
}
```

Generates the following:

```csharp
// Copyright (c) David Pine. All rights reserved.
// Licensed under the MIT License:
// https://github.com/IEvangelist/blazorators/blob/main/LICENSE
// Auto-generated by blazorators.

using System.Threading.Tasks;

#nullable enable
namespace Microsoft.JSInterop;

public partial interface IStorageServiceService
{
///
/// Source generated implementation of window.localStorage.length.
///
///
ValueTask Length
{
get;
}

///
/// Source generated implementation of window.localStorage.clear.
///
///
ValueTask ClearAsync();

///
/// Source generated implementation of window.localStorage.getItem.
///
///
ValueTask GetItemAsync(string key);

///
/// Source generated implementation of window.localStorage.key.
///
///
ValueTask KeyAsync(double index);

///
/// Source generated implementation of window.localStorage.removeItem.
///
///
ValueTask RemoveItemAsync(string key);

///
/// Source generated implementation of window.localStorage.setItem.
///
///
ValueTask SetItemAsync(string key, string value);
}
```

Notice, that since the generic method descriptors are not added generics are not supported. This is not yet implemented as I've been focusing on WebAssembly scenarios.

## Design goals 🎯

I was hoping to use the [TypeScript lib.dom.d.ts](https://github.com/microsoft/TypeScript/blob/315b807489b8ff3a892179488fb0c00398d9b2c3/lib/lib.dom.d.ts) bits as input. This input would be read, parsed, and cached within the generator. The generator code would be capable of generating extension methods on the `IJSRuntime`. Additionally, the generator will create object graphs from the well know web APIs.

Using the _lib.dom.d.ts_ file, we could hypothetically parse various TypeScript type definitions. These definitions could then be converted to C# counterparts. While I realize that not all TypeScript is mappable to C#, there is a bit of room for interpretation.

Consider the following type definition:

```typescript
/**
An object can programmatically obtain the position of the device.
It gives Web content access to the location of the device. This allows
a Web site or app to offer customized results based on the user's location.
*/
interface Geolocation {

clearWatch(watchId: number): void;

getCurrentPosition(
successCallback: PositionCallback,
errorCallback?: PositionErrorCallback | null,
options?: PositionOptions): void;

watchPosition(
successCallback: PositionCallback,
errorCallback?: PositionErrorCallback | null,
options?: PositionOptions): number;
}
```

> This is from the TypeScript repo, [lib.dom.d.ts file lines 5,498-5,502](https://github.com/microsoft/TypeScript/blob/315b807489b8ff3a892179488fb0c00398d9b2c3/lib/lib.dom.d.ts#L5497-L5502).

### Example consumption of source generator βœ”οΈ

Ideally, I would like to be able to define a C# class such as this:

```csharp
// Copyright (c) David Pine. All rights reserved.
// Licensed under the MIT License.

namespace Microsoft.JSInterop;

[JSAutoInterop(
TypeName = "Geolocation",
Implementation = "window.navigator.geolocation",
Url = "https://developer.mozilla.org/docs/Web/API/Geolocation")]
public partial interface IGeolocationService
{
}
```

The source generator will expose the `JSAutoInteropAttribute`, and consuming libraries will decorate their classes with it. The generator code will see this class, and use the `TypeName` from the attribute to find the corresponding type to implement.
With the type name, the generator will generate the corresponding methods, and return types. The method implementations will be extensions of the `IJSRuntime`.

The following is an example resulting source generated `IGeolocationService` object:

```csharp
namespace Microsoft.JSInterop;

public partial interface IGeolocationService
{
///
/// Source generated implementation of window.navigator.geolocation.clearWatch.
///
///
void ClearWatch(double watchId);

///
/// Source generated implementation of window.navigator.geolocation.getCurrentPosition.
///
///
/// The calling Razor (or Blazor) component.
/// Expects the name of a "JSInvokableAttribute" C# method with the following System.Action{GeolocationPosition}".
/// Expects the name of a "JSInvokableAttribute" C# method with the following System.Action{GeolocationPositionError}".
/// The PositionOptions value.
void GetCurrentPosition(
TComponent component,
string onSuccessCallbackMethodName,
string? onErrorCallbackMethodName = null,
PositionOptions? options = null)
where TComponent : class;

///
/// Source generated implementation of window.navigator.geolocation.watchPosition.
///
///
/// The calling Razor (or Blazor) component.
/// Expects the name of a "JSInvokableAttribute" C# method with the following System.Action{GeolocationPosition}".
/// Expects the name of a "JSInvokableAttribute" C# method with the following System.Action{GeolocationPositionError}".
/// The PositionOptions value.
double WatchPosition(
TComponent component,
string onSuccessCallbackMethodName,
string? onErrorCallbackMethodName = null,
PositionOptions? options = null)
where TComponent : class;
}

```

The generator will also produce the corresponding APIs object types. For example, the Geolocation API defines the following:

- `GeolocationService`
- `PositionOptions`
- `GeolocationCoordinates`
- `GeolocationPosition`
- `GeolocationPositionError`

```csharp
namespace Microsoft.JSInterop;

///
internal sealed class GeolocationService : IGeolocationService
{
private readonly IJSInProcessRuntime _javaScript = null;

public GeolocationService(IJSInProcessRuntime javaScript)
{
_javaScript = javaScript;
}

///
void IGeolocationService.ClearWatch(double watchId)
{
_javaScript.InvokeVoid("window.navigator.geolocation.clearWatch", watchId);
}

///
void IGeolocationService.GetCurrentPosition(
TComponent component,
string onSuccessCallbackMethodName,
string? onErrorCallbackMethodName,
PositionOptions? options)
{
_javaScript.InvokeVoid("blazorators.getCurrentPosition", DotNetObjectReference.Create(component), onSuccessCallbackMethodName, onErrorCallbackMethodName, options);
}

///
double IGeolocationService.WatchPosition(
TComponent component,
string onSuccessCallbackMethodName,
string? onErrorCallbackMethodName,
PositionOptions? options)
{
return _javaScript.Invoke("blazorators.watchPosition", new object[4]
{
DotNetObjectReference.Create(component),
onSuccessCallbackMethodName,
onErrorCallbackMethodName,
options
});
}
}
```

```csharp
using System.Text.Json.Serialization;

namespace Microsoft.JSInterop;

///
/// Source-generated object representing an ideally immutable GeolocationPosition value.
///
public class GeolocationPosition
{
///
/// Source-generated property representing the GeolocationPosition.coords value.
///
[JsonPropertyName("coords")]
public GeolocationCoordinates Coords
{
get;
set;
}

///
/// Source-generated property representing the GeolocationPosition.timestamp value.
///
[JsonPropertyName("timestamp")]
public long Timestamp
{
get;
set;
}

///
/// Source-generated property representing the GeolocationPosition.timestamp value,
/// converted as a in UTC.
///
[JsonIgnore]
public DateTime TimestampAsUtcDateTime => Timestamp.ToDateTimeFromUnix();
}

///
/// Source-generated object representing an ideally immutable GeolocationCoordinates value.
///
public class GeolocationCoordinates
{
///
/// Source-generated property representing the GeolocationCoordinates.accuracy value.
///
[JsonPropertyName("accuracy")]
public double Accuracy
{
get;
set;
}

///
/// Source-generated property representing the GeolocationCoordinates.altitude value.
///
[JsonPropertyName("altitude")]
public double? Altitude
{
get;
set;
}

///
/// Source-generated property representing the GeolocationCoordinates.altitudeAccuracy value.
///
[JsonPropertyName("altitudeAccuracy")]
public double? AltitudeAccuracy
{
get;
set;
}

///
/// Source-generated property representing the GeolocationCoordinates.heading value.
///
[JsonPropertyName("heading")]
public double? Heading
{
get;
set;
}

///
/// Source-generated property representing the GeolocationCoordinates.latitude value.
///
[JsonPropertyName("latitude")]
public double Latitude
{
get;
set;
}

///
/// Source-generated property representing the GeolocationCoordinates.longitude value.
///
[JsonPropertyName("longitude")]
public double Longitude
{
get;
set;
}

///
/// Source-generated property representing the GeolocationCoordinates.speed value.
///
[JsonPropertyName("speed")]
public double? Speed
{
get;
set;
}
}

///
/// Source-generated object representing an ideally immutable GeolocationPositionError value.
///
public class GeolocationPositionError
{
///
/// Source-generated property representing the GeolocationPositionError.code value.
///
[JsonPropertyName("code")]
public double Code
{
get;
set;
}

///
/// Source-generated property representing the GeolocationPositionError.message value.
///
[JsonPropertyName("message")]
public string Message
{
get;
set;
}

///
/// Source-generated property representing the GeolocationPositionError.PERMISSION_DENIED value.
///
[JsonPropertyName("PERMISSION_DENIED")]
public double PERMISSION_DENIED
{
get;
set;
}

///
/// Source-generated property representing the GeolocationPositionError.POSITION_UNAVAILABLE value.
///
[JsonPropertyName("POSITION_UNAVAILABLE")]
public double POSITION_UNAVAILABLE
{
get;
set;
}

///
/// Source-generated property representing the GeolocationPositionError.TIMEOUT value.
///
[JsonPropertyName("TIMEOUT")]
public double TIMEOUT
{
get;
set;
}
}

// Additional models omitted for brevity...
```

In addition to this `GeolocationExtensions` class being generated, the generator will also generate a bit of JavaScript. Some methods cannot be directly invoked as they define callbacks. The approach the generator takes is to delegate callback methods on a given `T` instance, with the `JSInvokable` attribute. Our generator should also warn when the corresponding `T` instance doesn't define a matching method name that is also `JSInvokable`.

```javascript
const getCurrentLocation =
(dotnetObj, successMethodName, errorMethodName, options) =>
{
if (navigator && navigator.geolocation) {
navigator.geolocation.getCurrentPosition(
(position) => {
dotnetObj.invokeMethodAsync(
successMethodName, position);
},
(error) => {
dotnetObj.invokeMethodAsync(
errorMethodName, error);
},
options);
}
};

// Other implementations omitted for brevity...
// But we'd also define a "watchPosition" wrapper.
// The "clearWatch" is a straight pass-thru, no wrapper needed.

window.blazorator = {
getCurrentLocation,
watchPosition
};
```

The resulting JavaScript will have to be exposed to consuming projects. Additionally, consuming projects will need to adhere to extension method consumption semantics. When calling generated extension methods that require .NET object references of type `T`, the callback names should be marked with `JSInvokable` and the `nameof` operator should be used to ensure names are accurate. Consider the following example consuming Blazor component:

```csharp
using Microsoft.AspNetCore.Components;
using Microsoft.JSInterop;
using Microsoft.JSInterop.Extensions;

namespace Example.Components;

// This is the other half of ConsumingComponent.razor
public sealed partial class ConsumingComponent
{
[Inject]
public IJSRuntime JavaScript { get; set; }

protected override async Task OnAfterRenderAsync(bool firstRender)
{
if (firstRender)
{
await JavaScript.GetCurrentPositionAsync(
this,
nameof(OnCoordinatesPermitted),
nameof(OnErrorRequestingCoordinates));
}
}

[JSInvokable]
public async Task OnCoordinatesPermitted(
GeolocationPosition position)
{
// TODO: consume/handle position.

await InvokeAsync(StateHasChanged);
}

[JSInvokable]
public async Task OnErrorRequestingCoordinates(
GeolocationPositionError error)
{
// TODO: consume/handle error.

await InvokeAsync(StateHasChanged);
}
}
```

## Pseudocode and logical flow ➑️

1. Consumer decorates a `static partial class` with the `JSAutoInteropAttribute`.
1. Source generator is called:
- `JavaScriptInteropGenerator.Initialize`
- `JavaScriptInteropGenerator.Execute`
1. The generator determines the `TypeName` from the attribute of the contextual class.
1. The `TypeName` is used to look up the corresponding TypeScript type definition.
1. If found, and a valid API - attempt source generation.

## Future work

- https://developer.mozilla.org/docs/Web/API/CredentialsContainer
- https://developer.mozilla.org/docs/Web/API/WakeLock
- https://developer.mozilla.org/docs/Web/API/Navigator/hid
- https://developer.mozilla.org/docs/Web/API/Web_Crypto_API

## Known limitations ⚠️

At the time of writing, only pure JavaScript interop is supported. It is a stretch goal to add the following (currently missing) features:

- Source generate corresponding (and supporting) JavaScript files.
- We'd need to accept a desired output path from the consumer, `JavaScriptOutputPath`.
- We would need to append all JavaScript into a single builder, and emit it collectively.
- Allow for declarative and custom type mappings, for example; suppose the consumer wants the API to use generics instead of `string`.
- We'd need to expose a `TypeConverter` parameter and allow for consumers to implement their own.
- We'd provide a default one for standard JSON serialization, `StringTypeConverter` (maybe make this the default).

## References and resources πŸ“‘

- [MDN Web Docs: Web APIs](https://developer.mozilla.org/docs/Web/API)
- [TypeScript DOM lib generator](https://github.com/microsoft/TypeScript-DOM-lib-generator)
- [ASP.NET Core Docs: Blazor JavaScript interop](https://docs.microsoft.com/aspnet/core/blazor/javascript-interoperability/call-javascript-from-dotnet)
- [Jared Parsons - GitHub Channel 9 Source Generators](https://github.com/jaredpar/channel9-source-generators)
- [.NET Docs: C# Source Generators](https://docs.microsoft.com/dotnet/csharp/roslyn-sdk/source-generators-overview)
- [Source Generators Cookbook](https://github.com/dotnet/roslyn/blob/main/docs/features/source-generators.cookbook.md)
- [Source Generators: Design Document](https://github.com/dotnet/roslyn/blob/main/docs/features/source-generators.md)

## Contributors ✨

Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/docs/en/emoji-key)):



Weihan Li
Weihan Li

πŸ’»
David Pine
David Pine

πŸ’» 🎨 πŸ‘€ πŸ€” ⚠️
Robert McLaws
Robert McLaws

πŸ’» πŸ› πŸ€”
Colin Dembovsky
Colin Dembovsky

πŸš‡ πŸ“¦
Tanay Parikh
Tanay Parikh

πŸ“–
Andreas MΓΌller
Andreas MΓΌller

πŸ› πŸ’»
Mahmudul Hasan
Mahmudul Hasan

πŸ’»


fabiansanchez18
fabiansanchez18

πŸ›
Sean Feldman
Sean Feldman

πŸ›
daver77
daver77

πŸ€”
Denny09310
Denny09310

πŸ’» ⚠️ πŸ€”

This project follows the [all-contributors](https://github.com/all-contributors/all-contributors) specification. Contributions of any kind are welcome!