Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

In @types/node, fs.WriteStream does not extend stream.Writable #564

Open
unarist opened this issue Sep 15, 2023 · 1 comment
Open

In @types/node, fs.WriteStream does not extend stream.Writable #564

unarist opened this issue Sep 15, 2023 · 1 comment

Comments

@unarist
Copy link

unarist commented Sep 15, 2023

In below code, stream.end() should be compiled as fs.WriteStream extends stream.Writable which has end() method. However, this won't be compiled without asInstanceOf[].

object Main {
  def main(args: Array[String]): Unit = {
    val stream = typings.node.fsMod.createWriteStream("output.txt")
    // stream.end()  // value end is not a member of typings.node.fsMod.WriteStream
    stream.asInstanceOf[typings.node.streamMod.Writable].end()
  }
}

ST generated source:

@JSImport("fs", "WriteStream")
@js.native
class WriteStream () extends StObject {
  def this(opts: WritableOptions) = this()
...

The corresponding d.ts should be this. I'm not sure why ScalablyTyped cannot resolve this extends, but maybe import * as stream from 'node:stream' is the case.

https://github.com/DefinitelyTyped/DefinitelyTyped/blob/61694a446616874377bc7b87b8644d8eed2da19a/types/node/v18/fs.d.ts#L450
https://github.com/DefinitelyTyped/DefinitelyTyped/blob/61694a446616874377bc7b87b8644d8eed2da19a/types/node/v18/fs.d.ts#L22
https://github.com/DefinitelyTyped/DefinitelyTyped/blob/61694a446616874377bc7b87b8644d8eed2da19a/types/node/v18/stream.d.ts#L1455-L1457

build configuration

plugins.sbt

addSbtPlugin("org.scala-js" % "sbt-scalajs" % "1.13.2")
addSbtPlugin("ch.epfl.scala" % "sbt-scalajs-bundler" % "0.21.1")
addSbtPlugin("org.scalablytyped.converter" % "sbt-converter" % "1.0.0-beta42")

build.sbt

scalaVersion := "2.13.11"

enablePlugins(ScalaJSPlugin, ScalaJSBundlerPlugin, ScalablyTypedConverterPlugin)
scalaJSUseMainModuleInitializer := true

Compile / npmDependencies += "@types/node" -> "18.16.19"

stTypescriptVersion := "5.0.4"
stStdlib := List("es2022")
stUseScalaJsDom := false
@unarist unarist changed the title When import node:fs, WriteStream not extends Writable In @types/node, fs.WriteStream does not extend stream.Writable Sep 15, 2023
@oyvindberg
Copy link
Collaborator

Thanks for the report!

I'm aware there has been come imperfections with those classes. One case I remember in particular is that deep in that complicated hierarchy there is a Duplex class which extends what ST needs to consider two classes. This is not permitted, so one of them is dropped.

This may be something different though, I'll look into eventually. For now the cast is a good workaround

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants