Adam S
07/24/2023, 10:06 PMexport type Extension = {extension: Extension} | readonly Extension[]
interface EditorStateConfig {
extensions?: Extension;
}
jw
07/24/2023, 11:33 PMis Array<*>
should workAdam S
07/25/2023, 6:49 AMAdam S
07/25/2023, 6:51 AMAdam S
07/25/2023, 6:52 AMArray.isArray()
should be added to JsArray, or would that be redundant and equivalent to is Array<*>
?turansky
07/25/2023, 8:30 AMis Array<*>
is preferable, equivalent isn’t requiredturansky
07/25/2023, 8:33 AMJsArray
- use it internally only for public extensions like this:
// not implemented now
fun JsIterator<T>.toTypedArray(): ReadonlyArray<T> =
JsArray.from(this)
turansky
07/25/2023, 8:41 AMexport type Extension = {extension: Extension} | readonly Extension[]
{extension: Extension} - looks like fine TS/JS sugar
readonly Extension[] - looks like what you will use in Kotlin
In Kotlin Wrappers we leave Kotlin signatures only if they used as input values (your case?)Adam S
07/25/2023, 8:42 AMJsArray.isArray()
isn’t easily able to infer types:
fun foo(arg: Any) {
if (JsArray.isArray(arg)) {
arg.size // ERROR: Unresolved reference: size
}
if (arg is Array<*>) {
arg.size // ✓ type is inferred correctly
}
}
Adam S
07/25/2023, 8:44 AMJsArray.isArray()
, but marking it as @Deprecated
& with ReplaceWith()
would help converting JS/TS code to Kotlin, and help developers to learn Kotlin?
@Deprecated("Using an `is Array<*>` typecheck is preferred", ReplaceWith("value is Array<*>"))
inline fun JsArray.Companion.isArray(value: dynamic): Boolean = value is Array<*>
Adam S
07/25/2023, 8:46 AMIn Kotlin Wrappers we leave Kotlin signatures only if they used as input values (your case?)Hmm I’m not sure I follow. Do you mean that I should only write Kotlin wrappers to handle the
readonly Extension[]
part of the union, because it’s more general, and the other part {extension: Extension}
most likely won’t be used directly?
Ignoring part of the type union certainly would make the code simpler, and help with writing wrappers.turansky
07/25/2023, 8:56 AM{extension: Extension}
you will need marker interface, which you probably won’t do 🙂Sergei Grishchenko
07/27/2023, 4:32 PMI totally disagree with it,is preferable, equivalent isn’t requiredis Array<*>
JsArray.isArray()
is essential check, we just need to support Kotlin contract for it to provide smart cast.Sergei Grishchenko
07/27/2023, 4:38 PM