Hey everyone, is there a way to get method docs an...
# javascript
p
Hey everyone, is there a way to get method docs and autocomplete for node_modules already installed, in KotlinJS module?
a
Sorry, I don't think I quite understand. Do you want autocomplete for Kotlin/JS libraries distributed via NPM?
p
I wanted to have some basic let’s say “parameters expected” by a function that is located in an NPM module. But then I thought that JS is full dynamic typing and autocomplete would not be a thing, but what about docs ?
For example, I have firebase-firestore npm module, and I would like to see the parameter expected by
functions.firestore.document(orderStatusDocument).onUpdate()
👍 1
Would something like this be possible?
a
I see.
The only way to achieve that is to describe the JS API in Kotlin, so that the compiler would have the info about the types and whatnot: https://kotlinlang.org/docs/reference/js-interop.html#external-modifier
Which is obviously not that simple.
Not long ago we've started a repo with such declarations: https://github.com/kotlin/js-externals
Check it out. The readme has links to a tool that converts TypeScript declarations to Kotlin
p
I am using Javascript, but If I understand correctly, adding those externals would allow it to work?
a
Well, let's say you have a
function foo(a) { return a * 10; }
defined elsewhere. You could then write
external fun foo(a: Int): Int
in Kotlin and use it normally.
p
Great! Would it be better to contribute those externals directly to this repo, since I guess Firebase is widely used!
a
Of course, you are very welcome to contribute 😃
p
Great, thank you a lot for your time and your help! Hopefully I will be able to contribute some
externals
🙂
a
👍
p
Hey @anton.bannykh, I opened a PR for Firebase 1.0.0 externals https://github.com/Kotlin/js-externals/pull/22
a
Thanks! I'll take a look 😃
🎉 1
👍 1