Skip to content

JavaScript / .NET Type Mappings

This table provides a quick reference for how different .NET and JavaScript runtime types and concepts are handled by the JS marshaller and type-definitions generator. Follow the links for more details about each topic.

TopicSummary
Basic typesstring => string
bool => boolean
byte, short, int, long, float, double => number
Null & undefined.NET null => JS undefined
JS null or undefined => .NET null
Classes & interfaces.NET classes can be constructed and used in JS. Class or interface instances are marshalled by reference. JS code can implement .NET interfaces.
Structs & tuples.NET structs can be constructed and used in JS. Struct instances and tuples are marshalled by value.
.NET Tuple<A,B> or ValueTuple<A,B> => JS [ A, B ] (array tuple)
Enums.NET enums are projected as TS non-const enums including reverse mappings.
Arrays & collections.NET T[] or IList<T> => JS T[]
.NET IDictionary<K,V> => JS Map<K,V>
.NET IEnumerable<T> => JS Iterable<T>
.NET Memory<byte> => JS Uint8Array
Delegates.NET Func<TValue, TReturn> => JS Function (TValue) => TRet
Streams.NET Stream => Node.js Duplex
Dates & times.NET DateTime => JS Date
.NET DateTimeOffset => JS Date
.NET TimeSpan => JS number (milliseconds)
Other special types.NET Guid => JS string
.NET BigInteger => JS bigint
Async & promises.NET Task<T> => JS Promise<T>
Ref & out params.NET ref and out params are returned via a result object:
C# bool F(ref string a, out int b) =>
JS f(a: string) => { a: string, b: int, result: boolean }
Generics*.NET generics are supported in JS, with special $ syntax and some limitations.
Extension methods*.NET extension methods are supported in JS.
Overloaded methods.NET overloaded methods can be called from JS, though overload resolution has some limitations.
Events.NET events are not yet implemented.
Fields.NET class or struct fields are not yet implemented. Use properties instead.
Exceptions.NET Exception is thrown as JS Error, with combined stack trace.
Namespaces*.NET namespaces are preserved on the node-api-dotnet module object:
import dotnet from 'node-api-dotnet';
dotnet.System.Console.WriteLine()

* These are only supported with the dynamic invocation scenario.

Released under the MIT license