Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature Request: Option to Generate TypeScript as export interface or export type #408

Open
bigmommyelven opened this issue Dec 15, 2024 · 2 comments

Comments

@bigmommyelven
Copy link

bigmommyelven commented Dec 15, 2024

First of all, thank you for your fantastic work on this library!

I would like to suggest a feature enhancement that would allow users to choose between generating TypeScript definitions as export interface or export type. Currently, the generator produces TypeScript definitions in a specific format (e.g., class), but having the flexibility to toggle between interface and type would make this tool even more versatile and better aligned with different project requirements and coding styles.

Proposed Feature
Introduce an option (eg: [JSExport(AsInterface: true)]) that allows users to specify whether TypeScript definitions should be generated as:

[JSExport(AsInterface: true)]
public class SomeDto
{
	public string Name { get; set; }
}

// Typescript
export interface SomeDto
export type SomeType

Thanks

@jasongin
Copy link
Member

Maybe.. but can you easily work around this by declaring a C# interface for the class, which will then be exported as a TS interface?

@bigmommyelven
Copy link
Author

bigmommyelven commented Jan 11, 2025

Yes it does work. But when I called it from node env, it returns empty objects.

C#

[JSExport]
public interface IFSFile
{
	string Name { get; set; }
	string Path { get; set; }
	string RelativeUri { get; set; }
	long Size { get; set; }
	string CreationTime { get; set; }
	string LastModified { get; set; }
	bool IsFile { get; set; }
	string Extension { get; set; }
}

public static IFSFile[] GetFiles(string path)
	=> InternalGetFiles(path);

JS

const files = FileSystem.getFiles(folderPath);
console.log(files);

Output
[IFSFile {}, IFSFile {}, ...]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants