microsoft / microsoft/node-api-dotnet

C# records are translated to invalid TypeScript types because of the `<Clone>$` member

Open
#458 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
C#
Stars
783
Forks
80
PR merge metrics
No merged PRs in 30d

Description

Given C# code link this:

public class TestClass { public TestRecord Hello() => new TestRecord("x"); }

public record TestRecord(string Value);

... produces TS typing like this:

		export class TestRecord {
			constructor(Value: string);
			Value: string;
			ToString(): string;
			GetHashCode(): number;
			Equals(obj: unknown | undefined): boolean;
			Equals(other: NodeDotNetInterop.TestRecord | undefined): boolean;
			<Clone>$(): NodeDotNetInterop.TestRecord;
			Deconstruct(): { Value: string };
		}

... which is invalid TypeScript: compile error at the <Clone>$() line is "Unexpected token. A constructor, method, accessor, or property was expected".

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the provided C# record example and inspect the type-generation path that emits the TestRecord declaration. The fix is done when the generated TypeScript contains no invalid $ member and compiles successfully.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp, typescript
Domain
tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.