Is there a way to disallow extensions on a class?
Details in 🧵
Seth Madison
05/01/2023, 10:41 PM
The most performant way that I’ve found to parse JSON using KotlinJS is to use native
JSON.parse
to produce a
dynamic
, and then
unsafeCast
it to an exported class. This works great, and allows for code sharing across targets (contrasted with
external interface
). This looks like:
The problem is that you end up with an incomplete instance of the class, and so if there are extension functions defined on the class, they’ll crash at runtime.
I would like to define a
JsExport
class that cannot receive extensions so that users of the class don’t accidentally write code that will crash at runtime!
j
Jan
05/05/2023, 7:28 PM
Not exactly what you might want, but you could wrap into value class and avoid auto complete for default extensions 😅