小编mar*_*rko的帖子

分解函数参数对象和... rest

我想编写一个函数,该函数接受一个对象参数并捕获变量中所有剩余的参数。目的是允许函数接收命名参数(与位置参数相对),其中一些参数是可选的,并在函数中设置默认值。因此,用伪代码是这样的:

interface IMyProps {
  a: string
  b?: number
}

const myfun1 = (p: {a: string, b?:number, ...rest}) => {
  const {a, b = 'hello'} = p;
}
Run Code Online (Sandbox Code Playgroud)

在Typescript 2.0中实现此目标的最佳方法是什么?

typescript

11
推荐指数
2
解决办法
7832
查看次数

防止子字符串中的Bash单词拆分

如何防止Bash在子字符串中拆分单词?这是一个有点人为的例子来说明问题:

touch file1 'foo bar'
FILES="file1 'foo bar'"
ls -la $FILES
Run Code Online (Sandbox Code Playgroud)

是否有可能通过$ FILES中的ls命令将'foo bar'视为单个字符串,这将有效地导致与以下命令相同的行为?

ls -la file1 'foo bar'
Run Code Online (Sandbox Code Playgroud)

linux bash shell

7
推荐指数
1
解决办法
1764
查看次数

标签 统计

bash ×1

linux ×1

shell ×1

typescript ×1