-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmethod.js
42 lines (38 loc) · 965 Bytes
/
method.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
// @ts-check
/**
* @typedef {import ('.').Interface} Interface
* @implements {Interface}
*/
export class Implementation {
/**
* @see {@link Interface.firstOrRest}
* @template T
* @overload
* @param {T} value
* @returns {[T]} value packed in array
*/
/**
* @see {@link Interface.firstOrRest}
* @template T
* @overload
* @param {*} first
* @param {...T} rest
* @returns {T[]} array of parameters after the first
*/
/**
* @see {@link Interface.firstOrRest}
* @param {*} first First parameter
* @param {Array} rest Array of remaining parameters
* @returns {Array}
*/
firstOrRest(first, ...rest) {
return arguments.length > 1 ? rest : [first];
}
}
const { firstOrRest } = Implementation.prototype;
firstOrRest('first');
firstOrRest('first', 'second');
/**
* @see {@link Implementation.firstOrRest}
*/
const firstOrRestFunction = firstOrRest;