Skip to content
This repository was archived by the owner on Jul 30, 2024. It is now read-only.

Commit c8a9f95

Browse files
authored
Merge pull request #261 from exoego/overload-over-union
Prefer overload over union types
2 parents 83f7a76 + e00f994 commit c8a9f95

27 files changed

+546
-309
lines changed

app/nodejs-v14/src/main/scala/io/scalajs/nodejs/Assert.scala

Lines changed: 29 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,18 @@ trait Assert extends js.Object {
3131
def deepStrictEqual(actual: js.Any, expected: js.Any, message: String): Unit = js.native
3232
def deepStrictEqual(actual: js.Any, expected: js.Any): Unit = js.native
3333

34-
def doesNotReject(asyncFn: js.Function | js.Promise[_], error: js.RegExp | js.Function, message: String): Unit =
35-
js.native
36-
def doesNotReject(asyncFn: js.Function | js.Promise[_], error: js.RegExp | js.Function): Unit = js.native
37-
def doesNotReject(asyncFn: js.Function | js.Promise[_], message: String): Unit = js.native
38-
def doesNotReject(asyncFn: js.Function | js.Promise[_]): Unit = js.native
34+
def doesNotReject(asyncFn: js.Function, error: js.RegExp, message: String): Unit = js.native
35+
def doesNotReject(asyncFn: js.Function, error: js.RegExp): Unit = js.native
36+
def doesNotReject(asyncFn: js.Function, error: js.Function, message: String): Unit = js.native
37+
def doesNotReject(asyncFn: js.Function, error: js.Function): Unit = js.native
38+
def doesNotReject(asyncFn: js.Function, message: String): Unit = js.native
39+
def doesNotReject(asyncFn: js.Function): Unit = js.native
40+
def doesNotReject(asyncFn: js.Promise[_], error: js.RegExp, message: String): Unit = js.native
41+
def doesNotReject(asyncFn: js.Promise[_], error: js.RegExp): Unit = js.native
42+
def doesNotReject(asyncFn: js.Promise[_], error: js.Function, message: String): Unit = js.native
43+
def doesNotReject(asyncFn: js.Promise[_], error: js.Function): Unit = js.native
44+
def doesNotReject(asyncFn: js.Promise[_], message: String): Unit = js.native
45+
def doesNotReject(asyncFn: js.Promise[_]): Unit = js.native
3946

4047
/**
4148
* Asserts that the function block does not throw an error. See assert.throws() for more details.
@@ -44,10 +51,12 @@ trait Assert extends js.Object {
4451
* error is of a different type, or if the error parameter is undefined, the error is propagated back to the caller.
4552
* @example assert.doesNotThrow(block[, error][, message])
4653
*/
47-
def doesNotThrow(block: js.Function, error: js.RegExp | js.Function, message: String): Unit = js.native
48-
def doesNotThrow(block: js.Function, error: js.RegExp | js.Function): Unit = js.native
49-
def doesNotThrow(block: js.Function, message: String): Unit = js.native
50-
def doesNotThrow(block: js.Function): Unit = js.native
54+
def doesNotThrow(block: js.Function, error: js.RegExp, message: String): Unit = js.native
55+
def doesNotThrow(block: js.Function, error: js.RegExp): Unit = js.native
56+
def doesNotThrow(block: js.Function, error: js.Function, message: String): Unit = js.native
57+
def doesNotThrow(block: js.Function, error: js.Function): Unit = js.native
58+
def doesNotThrow(block: js.Function, message: String): Unit = js.native
59+
def doesNotThrow(block: js.Function): Unit = js.native
5160

5261
/**
5362
* @see https://nodejs.org/api/assert.html#assert_assert_fail_message
@@ -102,17 +111,17 @@ trait Assert extends js.Object {
102111
* of the message parameter. If the message parameter is undefined, a default error message is assigned.
103112
* @example assert.throws(block[, error][, message])
104113
*/
105-
def throws(block: js.Function, error: js.RegExp | js.Function | js.Object | Error, message: String): Unit = js.native
106-
def throws(block: js.Function, error: js.RegExp | js.Function | js.Object | Error): Unit = js.native
107-
108-
def rejects(asyncFn: js.Function | js.Promise[_],
109-
error: js.RegExp | js.Function | js.Object | Error,
110-
message: String
111-
): Unit = js.native
112-
def rejects(asyncFn: js.Function | js.Promise[_], error: js.RegExp | js.Function | js.Object | Error): Unit =
113-
js.native
114-
def rejects(asyncFn: js.Function | js.Promise[_], message: String): Unit = js.native
115-
def rejects(asyncFn: js.Function | js.Promise[_]): Unit = js.native
114+
def throws(block: js.Function, error: js.Object, message: String): Unit = js.native
115+
def throws(block: js.Function, error: js.Object): Unit = js.native
116+
117+
def rejects(asyncFn: js.Function, error: js.Object, message: String): Unit = js.native
118+
def rejects(asyncFn: js.Function, error: js.Object): Unit = js.native
119+
def rejects(asyncFn: js.Function, message: String): Unit = js.native
120+
def rejects(asyncFn: js.Function): Unit = js.native
121+
def rejects(asyncFn: js.Promise[_], error: js.Object, message: String): Unit = js.native
122+
def rejects(asyncFn: js.Promise[_], error: js.Object): Unit = js.native
123+
def rejects(asyncFn: js.Promise[_], message: String): Unit = js.native
124+
def rejects(asyncFn: js.Promise[_]): Unit = js.native
116125
}
117126

118127
/**

app/nodejs-v14/src/main/scala/io/scalajs/nodejs/StringDecoder.scala

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,14 @@ class StringDecoder(encoding: String) extends IEventEmitter {
2020
* Returns any trailing bytes that were left in the buffer.
2121
* @example decoder.end()
2222
*/
23-
def end(buffer: TypedArray[_, _] | DataView): String = js.native
24-
def end(): String = js.native
23+
def end(buffer: TypedArray[_, _]): String = js.native
24+
def end(buffer: DataView): String = js.native
25+
def end(): String = js.native
2526

2627
/**
2728
* Returns a decoded string.
2829
* @example decoder.write(buffer)
2930
*/
30-
def write(buffer: TypedArray[_, _] | DataView): String = js.native
31+
def write(buffer: TypedArray[_, _]): String = js.native
32+
def write(buffer: DataView): String = js.native
3133
}

app/nodejs-v14/src/main/scala/io/scalajs/nodejs/buffer/Buffer.scala

Lines changed: 45 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -97,49 +97,36 @@ class Buffer private[this] () extends Uint8Array( /* dummy to trick constructor
9797
*/
9898
def equals(otherBuffer: Uint8Array): Boolean = js.native
9999

100-
/**
101-
* Fills buf with the specified value. If the offset and end are not given, the entire buf will be filled.
102-
* This is meant to be a small simplification to allow the creation and filling of a Buffer to be done on a single line.
103-
*
104-
* @param value The value to fill buf with
105-
* @param offset Where to start filling buf. Default: 0
106-
* @param end Where to stop filling buf (not inclusive). Default: buf.length
107-
* @param encoding If value is a string, this is its encoding. Default: 'utf8'
108-
* @return A reference to buf
109-
* @see https://nodejs.org/api/buffer.html#buffer_buf_fill_value_offset_end_encoding
110-
*/
111-
def fill(value: Uint8Array | Int | String, offset: Int, end: Int, encoding: String): this.type = js.native
112-
def fill(value: Uint8Array | Int | String, offset: Int, end: Int): this.type = js.native
113-
def fill(value: Uint8Array | Int | String, offset: Int, encoding: String): this.type = js.native
114-
def fill(value: Uint8Array | Int | String, offset: Int): this.type = js.native
115-
def fill(value: Uint8Array | Int | String, encoding: String): this.type = js.native
116-
def fill(value: Uint8Array | Int | String): this.type = js.native
117-
118-
/**
119-
* Returns the index of the first occurrence of value in buf or -1 if buf does not contain value
120-
* @param value What to search for
121-
* @param byteOffset Where to begin searching in buf. Default: 0
122-
* @param encoding If value is a string, this is its encoding. Default: 'utf8'
123-
* @return The index of the first occurrence of value in buf or -1 if buf does not contain value
124-
* @example {{{ buf.indexOf(value[, byteOffset][, encoding]) }}}
125-
*/
126-
def indexOf(value: Buffer | Int | String, byteOffset: Int, encoding: String): Int = js.native
127-
def indexOf(value: Buffer | Int | String, byteOffset: Int): Int = js.native
128-
def indexOf(value: Buffer | Int | String, encoding: String): Int = js.native
129-
def indexOf(value: Buffer | Int | String): Int = js.native
130-
131-
/**
132-
* Equivalent to buf.indexOf() !== -1.
133-
* @param value What to search for
134-
* @param byteOffset Where to begin searching in buf. Default: 0
135-
* @param encoding If value is a string, this is its encoding. Default: 'utf8'
136-
* @return true if value was found in buf, false otherwise
137-
* @example {{{ buf.includes(value[, byteOffset][, encoding]) }}}
138-
*/
139-
def includes(value: Buffer | Int | String, byteOffset: Int, encoding: String): Boolean = js.native
140-
def includes(value: Buffer | Int | String, byteOffset: Int): Boolean = js.native
141-
def includes(value: Buffer | Int | String, encoding: String): Boolean = js.native
142-
def includes(value: Buffer | Int | String): Boolean = js.native
100+
def fill(value: Uint8Array, offset: Int, end: Int): this.type = js.native
101+
def fill(value: Uint8Array, offset: Int): this.type = js.native
102+
def fill(value: Uint8Array): this.type = js.native
103+
def fill(value: Int, offset: Int, end: Int): this.type = js.native
104+
def fill(value: Int, offset: Int): this.type = js.native
105+
def fill(value: Int): this.type = js.native
106+
def fill(value: String, offset: Int, end: Int, encoding: String): this.type = js.native
107+
def fill(value: String, offset: Int, end: Int): this.type = js.native
108+
def fill(value: String, offset: Int, encoding: String): this.type = js.native
109+
def fill(value: String, offset: Int): this.type = js.native
110+
def fill(value: String, encoding: String): this.type = js.native
111+
def fill(value: String): this.type = js.native
112+
113+
def indexOf(value: Buffer, byteOffset: Int): Int = js.native
114+
def indexOf(value: Buffer): Int = js.native
115+
def indexOf(value: Int, byteOffset: Int): Int = js.native
116+
def indexOf(value: Int): Int = js.native
117+
def indexOf(value: String, byteOffset: Int, encoding: String): Int = js.native
118+
def indexOf(value: String, byteOffset: Int): Int = js.native
119+
def indexOf(value: String, encoding: String): Int = js.native
120+
def indexOf(value: String): Int = js.native
121+
122+
def includes(value: Buffer, byteOffset: Int): Boolean = js.native
123+
def includes(value: Buffer): Boolean = js.native
124+
def includes(value: Int, byteOffset: Int): Boolean = js.native
125+
def includes(value: Int): Boolean = js.native
126+
def includes(value: String, byteOffset: Int, encoding: String): Boolean = js.native
127+
def includes(value: String, byteOffset: Int): Boolean = js.native
128+
def includes(value: String, encoding: String): Boolean = js.native
129+
def includes(value: String): Boolean = js.native
143130

144131
/**
145132
* Creates and returns an iterator of buf keys (indices).
@@ -148,18 +135,14 @@ class Buffer private[this] () extends Uint8Array( /* dummy to trick constructor
148135
*/
149136
def keys(): js.Iterator[Int] = js.native
150137

151-
/**
152-
* Identical to buf.indexOf(), except buf is searched from back to front instead of front to back.
153-
* @param value What to search for
154-
* @param byteOffset Where to begin searching in buf. Default: 0
155-
* @param encoding If value is a string, this is its encoding. Default: 'utf8'
156-
* @return The index of the last occurrence of value in buf or -1 if buf does not contain value
157-
* @example {{{ buf.lastIndexOf(value[, byteOffset][, encoding]) }}}
158-
*/
159-
def lastIndexOf(value: Buffer | Int | String, byteOffset: Int, encoding: String): Int = js.native
160-
def lastIndexOf(value: Buffer | Int | String, byteOffset: Int): Int = js.native
161-
def lastIndexOf(value: Buffer | Int | String, encoding: String): Int = js.native
162-
def lastIndexOf(value: Buffer | Int | String): Int = js.native
138+
def lastIndexOf(value: Buffer, byteOffset: Int): Int = js.native
139+
def lastIndexOf(value: Buffer): Int = js.native
140+
def lastIndexOf(value: Int, byteOffset: Int): Int = js.native
141+
def lastIndexOf(value: Int): Int = js.native
142+
def lastIndexOf(value: String, byteOffset: Int, encoding: String): Int = js.native
143+
def lastIndexOf(value: String, byteOffset: Int): Int = js.native
144+
def lastIndexOf(value: String, encoding: String): Int = js.native
145+
def lastIndexOf(value: String): Int = js.native
163146

164147
/**
165148
* Returns the amount of memory allocated for buf in bytes.
@@ -925,8 +908,11 @@ object Buffer extends js.Object {
925908
*
926909
* @see [[https://nodejs.org/api/buffer.html#buffer_class_method_buffer_bytelength_string_encoding]]
927910
*/
928-
def byteLength(string: String | TypedArray[_, _] | DataView | ArrayBuffer, encoding: String = "utf8"): Int =
929-
js.native
911+
def byteLength(string: String, encoding: String): Int = js.native
912+
def byteLength(string: String): Int = js.native
913+
def byteLength(string: TypedArray[_, _]): Int = js.native
914+
def byteLength(string: DataView): Int = js.native
915+
def byteLength(string: ArrayBuffer): Int = js.native
930916

931917
/**
932918
* Compares `buf1` to `buf2` typically for the purpose of sorting arrays of `Buffer` instances.
@@ -945,8 +931,8 @@ object Buffer extends js.Object {
945931
* @see [[https://nodejs.org/api/buffer.html#buffer_class_method_buffer_concat_list_totallength]]
946932
*
947933
*/
948-
def concat(list: js.Array[Buffer] | js.Array[Uint8Array], totalLength: Int): Buffer = js.native
949-
def concat(list: js.Array[Buffer] | js.Array[Uint8Array]): Buffer = js.native
934+
def concat[B <: Uint8Array](list: js.Array[B], totalLength: Int): Buffer = js.native
935+
def concat[B <: Uint8Array](list: js.Array[B]): Buffer = js.native
950936

951937
/**
952938
* When passed a reference to the .buffer property of a TypedArray instance, the newly created Buffer

app/nodejs-v14/src/main/scala/io/scalajs/nodejs/buffer/package.scala

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,9 @@ package object buffer {
2929
/**
3030
* Returns the actual byte length of a string. This is not the same as String.prototype.length since that returns
3131
* the number of characters in a string.
32-
*
33-
* @param encoding the optional encoding (default "utf8")
3432
*/
3533
@inline
36-
def byteLength(encoding: String = "utf8"): Int = Buffer.byteLength(buffer, encoding)
34+
def byteLength(encoding: String): Int = Buffer.byteLength(buffer)
3735

3836
/**
3937
* Returns the hex-formatted string

app/nodejs-v14/src/main/scala/io/scalajs/nodejs/crypto/Certificate.scala

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,12 @@ import scala.scalajs.js.|
99
@js.native
1010
@JSImport("crypto", "Certificate")
1111
object Certificate extends js.Object {
12-
def exportChallenge(spkac: String | BufferLike): Buffer = js.native
12+
def exportChallenge(spkac: String): Buffer = js.native
13+
def exportChallenge(spkac: BufferLike): Buffer = js.native
1314

14-
def exportPublicKey(spkac: String | BufferLike, encoding: String): Buffer = js.native
15-
def exportPublicKey(spkac: String | BufferLike): Buffer = js.native
15+
def exportPublicKey(spkac: String, encoding: String): Buffer = js.native
16+
def exportPublicKey(spkac: String): Buffer = js.native
17+
def exportPublicKey(spkac: BufferLike): Buffer = js.native
1618

1719
def verifySpkac(spkac: BufferLike): Boolean = js.native
1820
}

0 commit comments

Comments
 (0)