Scala.js-specific runtime library components for Scala 3, providing JavaScript-specific functionality and bridge components between Scala 3 and the Scala.js runtime environment
npx @tessl/cli install tessl/maven-org-scala-lang--scala3-library-sjs1-3@3.7.0The Scala 3 library compiled for JavaScript environments via Scala.js, providing the complete Scala 3 standard library API with JavaScript-specific runtime support and cross-platform compatibility. This library enables Scala 3 applications to run efficiently in web browsers and Node.js environments while maintaining type safety and performance.
build.sbt:libraryDependencies += "org.scala-lang" %%% "scala3-library" % "3.7.0"Standard Scala imports work seamlessly:
import scala.*
import scala.util.*
import scala.compiletime.*
import scala.quoted.*
import scala.deriving.*Package-specific imports:
import scala.scalajs.js.internal.UnitOps.given
import scala.caps.{Capability, cap}
import scala.util.boundary.{boundary, break}import scala.*
import scala.util.boundary
// Use Scala 3 tuples and named tuples
val coordinates: (Double, Double) = (1.5, 2.7)
val person = (name = "Alice", age = 30, city = "San Francisco")
// Immutable arrays with full API
val numbers = IArray(1, 2, 3, 4, 5)
val doubled = numbers.map(_ * 2)
// Union and intersection types
def process[T](value: String | Int): T | Unit = value match
case s: String => println(s"String: $s")
case i: Int => println(s"Number: $i")
// Boundary-based control flow
boundary:
for i <- 1 to 100 do
if i > 50 then break(i)The Scala 3 library for Scala.js is organized around several key architectural components:
|), intersection types (&), and enhanced tuple systemIArray) and enhanced tuple operationsFoundation types including union types, intersection types, tuples, named tuples, equality system, and structural types. Essential for all Scala 3 programming with advanced type features.
type |[A, B] = A | B // Union types
type &[A, B] = A & B // Intersection types
sealed trait Tuple extends Product
case object EmptyTuple extends Tuple
sealed abstract class *:[+H, +T <: Tuple] extends NonEmptyTuple
trait CanEqual[-L, -R]
trait MatchableHigh-performance immutable arrays with covariant types and comprehensive collection operations. Provides JavaScript-optimized implementations of standard collection patterns.
opaque type IArray[+T] = Array[? <: T]
object IArray:
def empty[T]: IArray[T]
def apply[T](elems: T*): IArray[T]
def fill[T](n: Int)(elem: => T): IArray[T]
def tabulate[T](n: Int)(f: Int => T): IArray[T]Compile-time operations, quoted expressions, and macro support. Enables powerful metaprogramming with type-safe code generation and compile-time computation.
// Compile-time operations
inline def constValue[T]: T
inline def summonInline[T]: T
inline def error(msg: String): Nothing
// Quoted expressions
abstract class Expr[+T]
trait Quotes
// Type-level operations
type ToString[X] <: String
type +[X <: Int, Y <: Int] <: IntMirror-based generic programming for automatic derivation of type class instances. Supports both sum types (enums) and product types (case classes).
sealed trait Mirror:
type MirroredMonoType
type MirroredLabel <: String
type MirroredElemLabels <: Tuple
trait Mirror.Sum extends Mirror:
def ordinal(x: MirroredMonoType): Int
trait Mirror.Product extends Mirror:
def fromProduct(p: scala.Product): MirroredMonoTypeExperimental capture checking system for capability-safe programming. Provides fine-grained control over side effects and resource access.
trait Capability extends Any
object cap extends Capability
erased class CanThrow[-E <: Exception] extends Capability
sealed trait Contains[+C, R]Boundary-based control flow, utility types, and helper functions. Includes structured exception-like control flow and advanced utility classes.
// Boundary control flow
object boundary:
def apply[T](body: Label[T] ?=> T): T
def break[T](value: T)(using Label[T]): Nothing
// Utility types
final class NotGiven[+T]
sealed trait TupledFunction[F, G]Comprehensive annotation system including experimental features, macro annotations, and compiler hints. Supports both behavioral annotations and metaprogramming constructs.
class experimental extends StaticAnnotation
class targetName(name: String) extends StaticAnnotation
trait MacroAnnotation extends StaticAnnotation:
def transform(definition: Any, companion: Option[Any]): List[Any]JavaScript-specific runtime support and Scala.js interoperability. Provides the bridge between Scala 3 language features and JavaScript runtime environment.
// Scala.js specific operations
object UnitOps:
given unitOrOps[A](x: A | Unit): js.UndefOrOps[A]
// Runtime support
object Scala3RunTime
sealed abstract class AnonFunctionXXL extends scala.runtime.FunctionXXLCore types used throughout the API:
// Foundation types
abstract class AnyKind
trait Matchable
// Tuple types
sealed trait Tuple extends Product
case object EmptyTuple extends Tuple
sealed trait NonEmptyTuple extends Tuple
sealed abstract class *:[+H, +T <: Tuple] extends NonEmptyTuple
// Opaque types
opaque type IArray[+T] = Array[? <: T]
opaque type NamedTuple[N <: Tuple, +V <: Tuple] = V
// Function types
trait PolyFunction
abstract class Conversion[-T, +U] extends Function1[T, U]
// Meta types
abstract class Expr[+T]
trait Type[T]