Skip to content

[browser] JSImport can't do Enums #97375

Open
@eeegs

Description

@eeegs

Description

Enums can't be formally marshalled across to javascript nor do they marshal when part of an object[] being passed over from c# for function.apply(this, args) to use.

Reproduction Steps

Try and define this proxy stub;

[JSImport("getEnumValue", "Code")]
internal static partial int GetEnumValue([JSMarshalAs<JSType.Number>]NumberTypes number);

and you get this error:

Severity	Code	Description	Project	File	Line	Suppression State	Details
Error	SYSLIB1072	The type 'TestHost.Pages.Simple.NumberTypes' is not supported by source-generated JavaScript interop. The generated source will not handle marshalling of parameter 'number'. For more information see https://aka.ms/dotnet-wasm-jsinterop	19	Active	

Enums when defining directly or indirectly, should just auto marshal as a number.

Expected behavior

Enum value turns up in javascript as a number

Actual behavior

Can't compile, but if passing as an object, a proxy to the enum object is passed in.

Regression?

Nope, came with the new feature in .net 7

Known Workarounds

No exact ones.

Configuration

.net8, blazor, x64

Other information

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions