getParamNames

说明

获取函数的形参名称数组

源码

用法

getParamNames.test.ts
1
import { getParamNames } from "../../utility/function/getParamNames";
2
3
describe('getParamNames', () => {
4
test("getParamsNames should receive lots of parameters and return the array of each parameter's name.", () => {
5
const received = [
6
function (..._args: any[]) { },
7
function func1(_name: string, _age: number) { },
8
function func2(_name: string, _age: number, _address: string, ..._args: any[]) { },
9
];
10
const expected = [
11
[],
12
['_name', '_age'],
13
['_name', '_age', '_address'],
14
];
15
16
for (const [i, v] of received.entries()) {
17
const current = getParamNames(v);
18
expect(current).toEqual(expected[i]);
19
}
20
});
21
});
Copied!
最近更新 1yr ago
复制链接