<< Back to previous view

[CLJS-2928] Externs inference: Consider inheritance Created: 07/Oct/18  Updated: 07/Oct/18

Status: Open
Project: ClojureScript
Component/s: None
Affects Version/s: None
Fix Version/s: None

Type: Enhancement Priority: Major
Reporter: Mike Fikes Assignee: Unassigned
Resolution: Unresolved Votes: 3
Labels: None


If a JavaScript type is inferred, "base" properties are not considered. A specific example is js/document, which gets inferred as js/HTMLDocument. If code makes use of any of the base properties, then an inference warning will get triggered, even though :advanced compilation is fine.

(ns test.infer)

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

(.-documentElement js/document)
$ clj -m cljs.main -co '{:infer-externs true}' -c test.infer
WARNING: Cannot resolve property documentElement for inferred type js/HTMLDocument in expression (. js/document -documentElement) at line 5 /Users/mfikes/Desktop/test-infer/src/test/infer.cljs

If you add -O advanced you can confirm that documentElement survives into the compiled artifact without being mangled.

Also, you can work around the issue by hinting the target as being the base type:

(.-documentElement ^js/Document js/document)

Perhaps there is some way to make use of the "extends" metadata in the externs in cases like these to check base types before emitting a warning (or by inferring the base type based on the property being accessed). Here is the extends metadata of interest in the example above: https://github.com/google/closure-compiler/blob/50713dceb16b369f8f317e5b49e8a9dec2b47496/externs/browser/w3c_dom2.js#L171

Generated at Fri Apr 26 01:19:49 CDT 2019 using JIRA 4.4#649-r158309.