Replies: 3 comments
-
Could you please share the JavaScript/TypeScript code which is trying to be mapped by this code? |
Beta Was this translation helpful? Give feedback.
-
https://unpkg.com/browse/[email protected]/dist/development/index.d.ts interface NavigateFunction {
(to: To, options?: NavigateOptions): void | Promise<void>;
(delta: number): void | Promise<void>;
}
declare function useNavigate(): NavigateFunction; Also, just found this convenient interface for looking up the types for a lib https://types.kubajastrz.com/ |
Beta Was this translation helpful? Give feedback.
-
The other alternative is to not use This is what Glutinum generates right now: [<AbstractClass>]
[<Erase>]
type Exports =
[<Import("useNavigate", "REPLACE_ME_WITH_MODULE_NAME")>]
static member useNavigate () : NavigateFunction = nativeOnly
[<AllowNullLiteral>]
[<Interface>]
type NavigateFunction =
[<Emit("$0($1...)")>]
abstract member Invoke: ``to``: To * ?options: NavigateOptions -> U2<unit, JS.Promise<unit>>
[<Emit("$0($1...)")>]
abstract member Invoke: delta: float -> U2<unit, JS.Promise<unit>> In a ideal world useNavigate.Invoke("to-somewhere", NavigateOptions(
replace = true
)
) when in TypeScript you would write useNavigate("to-somewhere", {
replace: true
}) You could perhaps optimise it even more by generating something like that [<AbstractClass>]
[<Erase>]
type Exports =
[<Emit("$0($1...)")>]
[<Import("useNavigate", "REPLACE_ME_WITH_MODULE_NAME")>]
abstract member Invoke: ``to``: To * ?options: NavigateOptions -> U2<unit, JS.Promise<unit>>
[<Emit("$0($1...)")>]
[<Import("useNavigate", "REPLACE_ME_WITH_MODULE_NAME")>]
abstract member Invoke: delta: float -> U2<unit, JS.Promise<unit>> |
Beta Was this translation helpful? Give feedback.
-
When writing bindings for something like a hook that returns a function, where the returned function takes a params object, it would be convenient to be able to define a delegate that uses
ParamObject
:The alternative is using a type with
Emit("$0($1...)")
(Maybe the second one could also be made prettier and less error prone to type with an
EmitApply
orEmitCall
helper?)Beta Was this translation helpful? Give feedback.
All reactions