glutinum-org / cli

Home Page:https://glutinum.net/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

different result for indexed type when inlined in interface field

joprice opened this issue · comments

When a type with an indexer is nested, a class type gets generated instead:

interface Options {
  [key: string]: string 
}

correctly generates

[<AllowNullLiteral>]
[<Interface>]
type Options =
    [<EmitIndexer>]
    abstract member Item: key: string -> string with get, set

However, with the definition inlined into a key:

interface OptionsInline {
   users: { [key: string]: string }
}

It generates

[<AllowNullLiteral>]
[<Interface>]
type OptionsInline =
    abstract member users: OptionsInline.users with get, set

module OptionsInline =

    [<Global>]
    [<AllowNullLiteral>]
    type users
        [<ParamObject; Emit("$0")>]
        (
            Item: string
        ) =

        member val Item : string = nativeOnly with get, set

Aliasing the type works as expected:

interface OptionsAliased {
   users: Options
}
[<AllowNullLiteral>]
[<Interface>]
type Options =
    [<EmitIndexer>]
    abstract member Item: key: string -> string with get, set

[<AllowNullLiteral>]
[<Interface>]
type OptionsAliased =
    abstract member users: Options with get, set

Indeed, the AST for both of them is a little different:

CleanShot 2024-06-17 at 16 26 07

We probably need to detect IndexSignature when inside of a TypeLiteral and not just Interface.