Skip to content

.NET Interop #1186

Description

@bbqchickenrobot

Do we have to declare / import every single .net type we want to work with?! With every signature?

// Call .NET types directly from TypeScript
@DotNetType("System.Text.StringBuilder")
declare class StringBuilder {
    constructor();
    append(value: string): StringBuilder;
    toString(): string;
}

@DotNetType("System.TimeSpan")
declare class TimeSpan {
    static fromHours(value: number): TimeSpan;
    readonly totalMinutes: number;
}

const sb = new StringBuilder();
sb.append("1.5 hours = ");
sb.append(`${TimeSpan.fromHours(1.5).totalMinutes} minutes`);
console.log(sb.toString());

I work with hundreds and hundreds of .net types daily - this is a monumental task to declare each type. Is there a plan to auto-import this with usings statements down the road ? maybe a usings.ts file so that the regular .ts files don't even need an import statements? Or perhaps a source generator to read the BCL from an import statement and generate a typescript .net definitions on build (caching of course)? Not sure how F# does it - but that's a massive hurdle to using this library and will stifle adoption outside of a playground scenario.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions