Fork me on GitHub
#cljs-dev
<
2022-11-10
>
mhuebert13:11:14

Is there a way to hint a deftype field so that it will not be renamed by the closure compiler? eg something like (deftype MyType [^js myFieldThatWillNotBeRenamed]) (which doesn’t work)

borkdude13:11:29

@mhuebert doesn't this happen when you use that field somewhere with (.-myFieldThatWillNotBeRenamed ^js (MyType. "foo")) - at least with shadow-cljs this seems to be the case

mhuebert13:11:43

@borkdude yeah I would expect that to work

mhuebert13:11:53

I have a use case where I wouldn’t otherwise have a reason to access or set it in my code

mhuebert13:11:14

(using a deftype as a react ref, which expects a “current” property)

borkdude13:11:21

needless to say probably, but usually a protocol is the way to access stuff from deftypes

borkdude13:11:27

or you could turn it into a record

dnolen13:11:07

@mhuebert externs work and have always worked

1
👍 1
dnolen13:11:32

my.ns.MyType.myFieldThatWillNotBeRenamed;

mhuebert13:11:15

also got it to work like this, by using (set! (.-currentThing ^js o)) inside the deftype (instead of just currentThing)

dnolen15:11:25

right that generates Object.currentThing; export for you