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

Adapt generated code to be erase methods which are subset of others #30

Open
MangelMaxime opened this issue Jan 9, 2024 · 0 comments
Open

Comments

@MangelMaxime
Copy link
Contributor

TypeScript documentation:

export class Logger {
    log(value : string, prefix? : string): void
    log(value : string, prefix? : string, time? : Boolean): void
}

translates into

module rec Glutinum

open Fable.Core
open System

[<Erase>]
type Exports =
    interface end

[<AllowNullLiteral>]
type Logger =
    abstract member log: value: string * ?prefix: string -> unit
    abstract member log: value: string * ?prefix: string * ?time: bool -> unit

However this is causing issues when trying to consume the API from F#.

let logger = unbox<Logger> null

logger.log("Hello, world!")

CleanShot 2024-01-09 at 22 58 20@2x

In the past, I know that when doing #29 some unwrapping of union type arguments I add to remove or add others version of the method to have access to the full API and make F# happy.

For the example, used in this issue we should in theory be able to remove the method which is subset of the other one:

[<AllowNullLiteral>]
type Logger =
-     abstract member log: value: string * ?prefix: string -> unit
    abstract member log: value: string * ?prefix: string * ?time: bool -> unit

Example of npm package using this features:

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

No branches or pull requests

1 participant