glutinum-org / cli

Home Page:https://glutinum.net/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Support `create<T extends keyof TypeMap>`

MangelMaxime opened this issue · comments

TypeScript documentation:

interface TypeMap {
    "string": string;
    "number": number;
    "bool": Boolean;
}

export declare function create<T extends keyof TypeMap>(
    tagName: T,
): TypeMap[T];


// Usage
const t : string = create("string");
const t2 : string = create("number"); // Error because number is not assignable to string

translates into something like

[<Erase>]
type Exports =
    [<Import("create", "module")>]
    static member create (tagName: Exports.create.T) : obj = nativeOnly

module Exports =

    module create =

        [<RequireQualifiedAccess>]
        [<StringEnum(CaseRules.None)>]
        type T =
            | [<CompiledName("string")>] string
            | [<CompiledName("number")>] number
            | [<CompiledName("bool")>] bool

[<AllowNullLiteral>]
[<Interface>]
type TypeMap =
    abstract member string: string with get, set
    abstract member number: float with get, set
    abstract member bool: bool with get, set

Example of npm package using this features:

Leaflet