<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0">
<channel>
<title>Clojure Q&amp;A - Recent questions tagged externs</title>
<link>https://ask.clojure.org/index.php/tag/externs</link>
<description></description>
<item>
<title>some-&gt; intermediate step suppresses JavaScript extern inference</title>
<link>https://ask.clojure.org/index.php/15232/some-intermediate-suppresses-javascript-extern-inference</link>
<description>&lt;p&gt;ClojureScript does not seem to infer an extern or emit an inference warning for a JavaScript method call after an intermediate &lt;code&gt;some-&amp;gt;&lt;/code&gt; step. &lt;/p&gt;
&lt;p&gt;Advanced compilation then renames the call across an npm boundary and causes a runtime error.&lt;/p&gt;
&lt;p&gt;I reproduced this with ClojureScript 1.12.145 and with an uberjar built from &lt;a rel=&quot;nofollow&quot; href=&quot;https://github.com/clojure/clojurescript/commit/b45dff9f9aeb506864ecb5618ba686ff2ee8de77&quot;&gt;master at &lt;code&gt;b45dff9f&lt;/code&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h3&gt;Reproduction&lt;/h3&gt;
&lt;p&gt;&lt;code&gt;deps.edn&lt;/code&gt;:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;{:deps {org.clojure/clojure {:mvn/version &quot;1.12.4&quot;}
        org.clojure/clojurescript {:mvn/version &quot;1.12.145&quot;}}
 :paths [&quot;src&quot;]}
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;code&gt;package.json&lt;/code&gt;:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;{&quot;dependencies&quot;:{&quot;formatter-lib&quot;:&quot;file:formatter-lib&quot;},&quot;private&quot;:true}
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;code&gt;formatter-lib/package.json&lt;/code&gt;:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;{&quot;main&quot;:&quot;index.js&quot;,&quot;name&quot;:&quot;formatter-lib&quot;,&quot;version&quot;:&quot;1.0.0&quot;}
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;code&gt;formatter-lib/index.js&lt;/code&gt;:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;class Formatter {
  constructor(value) {
    this.value = value;
  }

  toPattern(pattern) {
    return `${this.value}:${pattern}`;
  }
}

module.exports = (value) =&amp;gt; new Formatter(value);
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;code&gt;src/repro/core.cljs&lt;/code&gt;:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;(ns repro.core
  (:require [&quot;formatter-lib&quot; :as formatter]))

(set! *warn-on-infer* true)

(defn -main []
  (println (some-&amp;gt; (formatter 42) identity (.toPattern &quot;yyyy&quot;))))

(set! *main-cli-fn* -main)
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;code&gt;build.edn&lt;/code&gt;:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;{:infer-externs true
 :install-deps false
 :main repro.core
 :npm-deps {&quot;formatter-lib&quot; &quot;1.0.0&quot;}
 :optimizations :advanced
 :output-dir &quot;target/out&quot;
 :output-to &quot;target/main.js&quot;
 :target :nodejs}
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Run:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;npm install
clojure -M -m cljs.main -co build.edn -c repro.core
node target/main.js
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The compile emits no extern inference warning. The generated call is renamed and Node fails:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;TypeError: a.Yb is not a function
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The same result occurs with the uberjar built from master:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;java -cp /path/to/clojurescript/target/cljs.jar:src \
  clojure.main -m cljs.main -co build.edn -c repro.core
node target/main.js
&lt;/code&gt;&lt;/pre&gt;
&lt;h3&gt;Control&lt;/h3&gt;
&lt;p&gt;Removing the intermediate &lt;code&gt;identity&lt;/code&gt; step:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;(println (some-&amp;gt; (formatter 42) (.toPattern &quot;yyyy&quot;)))
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;causes the compiler to infer the extern:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;WARNING: Adding extern to Object for property toPattern due to ambiguous expression
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The generated method remains &lt;code&gt;toPattern&lt;/code&gt;, and Node prints:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;42:yyyy
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;I expected the version with the intermediate step to infer the same extern, or at least emit a warning that the target type could not be inferred.&lt;/p&gt;
</description>
<category>ClojureScript</category>
<guid isPermaLink="true">https://ask.clojure.org/index.php/15232/some-intermediate-suppresses-javascript-extern-inference</guid>
<pubDate>Mon, 07 Sep 2026 23:32:03 +0000</pubDate>
</item>
</channel>
</rss>