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

Support generic function parameters #67

Closed
Skleni opened this issue Jun 3, 2022 · 2 comments · Fixed by #76
Closed

Support generic function parameters #67

Skleni opened this issue Jun 3, 2022 · 2 comments · Fixed by #76
Labels
enhancement New feature or enhancement help wanted Community help is most appreciated

Comments

@Skleni
Copy link
Contributor

Skleni commented Jun 3, 2022

The following code leads to an invalid TypeScript type definition:

namespace Repro;

public class GenericType<T>
{
    public T Value { get; set; }
}

public static partial class Program
{
    public static void Main()
    {
    }

    [JSInvokable]
    public static void Function(GenericType<string> param)
    {
    }
}

This generates the following definitions in dotnet.d.ts:

export namespace Repro {
    export class GenericType`1 {
        value?: string;
    }
}
export namespace Repro {
    export function Function(model: Repro.GenericType`1): void;
}

I think it should be possible to generate generic type definitions. If it's not, however, a mechanism that would allow me to specify that a given type should just be typed as any would also work for me. First I thought about an attribute, but that wouldn't work for third party types, so it's probably not the best solution.

@Skleni
Copy link
Contributor Author

Skleni commented Jun 3, 2022

If it helps, I could try to implement it myself and create a pull request.

@elringus elringus added enhancement New feature or enhancement help wanted Community help is most appreciated labels Jun 3, 2022
@elringus elringus added this to the First stable release milestone Jun 3, 2022
@elringus
Copy link
Owner

elringus commented Jun 3, 2022

Hey, Thanks for the suggestion! That's definitely something I'd like to support, though I have no need for this in my own project at this time. A pull request would be appreciated.

Most likely it's just the matter of supporting generic type case here: https://github.com/Elringus/DotNetJS/blob/main/DotNet/Packer/DeclarationGenerator/TypeConverter.cs

Tests for this can be added here: https://github.com/Elringus/DotNetJS/blob/main/DotNet/Packer.Test/DeclarationTest.cs

Skleni added a commit to Skleni/DotNetJS that referenced this issue Jul 1, 2022
Skleni added a commit to Skleni/DotNetJS that referenced this issue Jul 1, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or enhancement help wanted Community help is most appreciated
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants