Improve `js.Promise` facade
See original GitHub issueCurrently, the facade for js.Promise
is implemented as a class:
But in Typescript, it’s modeled as an interface, separately from the constructors:
https://github.com/microsoft/TypeScript/blob/main/lib/lib.es5.d.ts#L1446
This results in transpilation problems in ScalablyTyped, where a typescript facade wants to implement the Promise
interface but instead tries to inherit from a class requiring a constructor:
https://github.com/ScalablyTyped/Converter/issues/404#issuecomment-1023659519
The relevant parts of generated code look like this:
// generated valid typescript code
export type PrismaPromise<A> = Promise<A> & {[prisma]: true}
export class Prisma__WorkspaceClient<T> implements PrismaPromise<T> {
[prisma]: true;
...
// transpiled to Scala
@js.native
trait PrismaPromise[A] extends js.Promise[A]
@JSImport("generated-prisma-client", "Prisma.Prisma__WorkspaceClient")
@js.native
class PrismaWorkspaceClient[T] protected () extends PrismaPromise[T] {
...
compile error:
[error] not enough arguments for constructor Promise: (executor: scala.scalajs.js.Function2[scala.scalajs.js.Function1[T | scala.scalajs.js.Thenable[T], _], scala.scalajs.js.Function1[Any, _], _]): scala.scalajs.js.Promise[T].
[error] Unspecified value parameter executor.
[error] L16: class PrismaWorkspaceClient[T] protected () extends PrismaPromise[T] {
[error] ^
I’m wondering if we could improve the Promise facade to be more similar to the typescript facade, which is probably also closer to the specs.
For reference, the Promise
specification:
https://tc39.es/ecma262/multipage/control-abstraction-objects.html#sec-properties-of-the-promise-prototype-object
Issue Analytics
- State:
- Created a year ago
- Comments:8 (6 by maintainers)
Top GitHub Comments
Ok, thanks. A scala implementation of Promise was absolutely not something I considered, but it’s a fair point. With that constraint I suggest we close this issue.
I suppose I can make this work on my side by analyzing the inheritance hierarchy for every class and infer an
extends js.Promise(js.native, js.native) with <original inheritance>
. I’ll likely skip that work and just usejs.Thenable
instead.From the existence of The Promise Constructor. If something has a constructor, it’s a class (these two ideas are one and the same thing in ES).
It depends on your (and their) definition of correct or wrong. What I can tell you is that making it a trait in Scala.js would be wrong for the definition of Scala.js.