Open lukaszkrzywizna opened 9 months ago
A workaround is to use window.clearTimeout
you can use:
open Browser
open Browser
let clearTimeout () =
None
|> Option.iter window.clearTimeout
It will generates:
import { iterate } from "fable-library-js/Seq.js";
import { toArray } from "fable-library-js/Option.js";
export function clearTimeout() {
iterate((handle) => {
window.clearTimeout(handle);
}, toArray(void 0));
}
You could also create a local alias to the function:
open Browser
let jsClearTimeout = Fable.Core.JS.clearTimeout
let inline jsClearTimeoutInlined delay = Fable.Core.JS.clearTimeout delay
let clearTimeout () =
None
|> Option.iter jsClearTimeout
let clearTimeout2 () =
None
|> Option.iter jsClearTimeoutInlined
I think current Fable mechanism for detecting name clashing don't catch this situation because clearTimeout
is decorated with [<Global>]
.
Description:
When defining a local F# function in a Fable project with a name that matches a global JavaScript function (e.g.,
setTimeout
,clearTimeout
), Fable always references the local function, even in contexts where the global JavaScript function is intended to be used. This behavior can lead to unexpected errors, such as "RangeError: Maximum call stack size exceeded", due to recursive calls when the local function tries to use the global one indirectly.Repro code:
Expected and actual results:
Expected: The
clearTimeout
call within the localclearTimeout
function should reference the global JavaScriptclearTimeout
function, allowing for the proper clearing of timeouts set withsetTimeout
.Actual: The local
clearTimeout
function is recursively calling itself instead of the global JavaScriptclearTimeout
, leading to a "RangeError: Maximum call stack size exceeded" error.Suggested Solution:
It might be beneficial for Fable to provide clearer warnings or errors during compilation when local function names shadow global JavaScript functions, or potentially offer a way to explicitly reference global functions in such cases.
Related information: