为了更好的可读性,我试图找到一种在函数声明之外直观地声明 TypeScript 函数参数的简写方式。我目前有这个功能:
function processPerson(firstName: string, lastName: string, age: number, city: string, country: string, yetAnotherArgument: string) {}
Run Code Online (Sandbox Code Playgroud)
(请注意,我不希望创建对象并将其传递给函数)。有没有办法让我像这样指定函数参数?
type MyArguments = {
firstName: string,
lastName: string,
age: number,
city: string,
country: string,
yetAnotherArgument: string
}
function doSomething(...arguments: MyArguments) {}
Run Code Online (Sandbox Code Playgroud) 是否有任何测试框架支持使用新 ES 模块语法的测试?我有一个 JS 应用程序,它大量使用.mjs带有 ES 模块的文件。我尝试了 Jest 和 Jasmine,当我尝试为我的应用程序编写运行测试时,它们都会抛出错误。我需要测试这个文件:
数学.mjs
export function add(a, b) {
return a + b;
}
Run Code Online (Sandbox Code Playgroud)