glutinum-org / cli

https://glutinum.net/
59 stars 6 forks source link

generics are not added to inline type definition #148

Open joprice opened 1 week ago

joprice commented 1 week ago

Issue created from Glutinum Tool

Glutinum version - 0.11.0-preview

TypeScript

type Callback<Param, AtomType> = (event: {
      type: 'CREATE' | 'REMOVE';
      param: Param;
      atom: AtomType;
  }) => void;

FSharp

module rec Glutinum

open Fable.Core
open Fable.Core.JsInterop
open System

[<AllowNullLiteral>]
[<Interface>]
type Callback<'Param, 'AtomType> =
    [<Emit("$0($1...)")>]
    abstract member Invoke: event: Callback.event -> unit

module Callback =

    [<Global>]
    [<AllowNullLiteral>]
    type event
        [<ParamObject; Emit("$0")>]
        (
            ``type``: Callback.event.``type``,
            param: 'Param,
            atom: 'AtomType
        ) =

        member val ``type`` : Callback.event.``type`` = nativeOnly with get, set
        member val param : 'Param = nativeOnly with get, set
        member val atom : 'AtomType = nativeOnly with get, set

    module event =

        [<RequireQualifiedAccess>]
        [<StringEnum(CaseRules.None)>]
        type ``type`` =
            | CREATE
            | REMOVE

Problem description

When an inlined js type is extracted into a module, like Callback.event above, the generics present on the outer type are not applied to the type definition or the use-site, resulting in the warning:

warning FSHARP: This construct causes code to be less generic than indicated by the type annotations. The type variable 'Param has been constrained to be type 'obj'. (code 64)

The warning is removed if the generics are propagated by modifying the definition to

type event<'Param, 'AtomType>

and the usage to

abstract member Invoke: event: Callback.event<'Param, 'AtomType> -> unit