Sergey
06/22/2023, 10:37 AMsuspend fun readdir(
path: PathLike,
options: ObjectEncodingOptions,
/* {
withFileTypes: true;
} */
): ReadonlyArray<Dirent> =
readdirAsync(
path = path,
options = options,
).await()
https://github.com/JetBrains/kotlin-wrappers/blob/master/kotlin-node/src/jsMain/generated/node/fs/readdir.kt
has arg "options" with interface "ObjectEncodingOptions" uses
@JsName("readdir")
external fun readdirAsync(
path: PathLike,
options: ObjectEncodingOptions,
/* {
withFileTypes: true;
} */
): Promise<ReadonlyArray<Dirent>>
that also has arg "options" with interface and commented field withFileTypes
sealed external interface ObjectEncodingOptions {
var encoding: node.buffer.BufferEncoding?
}
https://github.com/JetBrains/kotlin-wrappers/blob/master/kotlin-node/src/jsMain/generated/node/fs/readdirAsync.kt
and nodejs types has more complete interface with option withFileTypes and recursive
function readdir(
path: PathLike,
options?:
| (ObjectEncodingOptions & {
withFileTypes?: false | undefined;
recursive?: boolean | undefined;
})
| BufferEncoding
| null
): Promise<string[]>;
https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/types/node/fs/promises.d.ts#L258
I need option.withFileTypes to receive Dirent instead Strings and looks like it should be default for this function implementation, because in another case it returns string and throw error when I'm trying to call "isFIle" function
By the way, it works nice when I'm using it like this:
val files: ReadonlyArray<Dirent> = readdir("...", object {
@JsName("withFileTypes")
val withFileTypes = true
} as ObjectEncodingOptions)
turansky
06/22/2023, 1:49 PMSergey
06/22/2023, 6:28 PMturansky
06/25/2023, 7:41 AM