小编sam*_*mdd的帖子

检查接口是否有必填字段

是否可以使用 Typescript 的条件类型检查接口是否具有必填字段?

type AllRequired = { a: string; b: string }
type PartiallyRequired = { a: string; b?: string }
type Optional = { a?: string; b?: string }

// Is it possible to change this, so the below works
type HasRequiredField<T> = T extends {} ? true : false

type A = HasRequiredField<AllRequired> // true
type B = HasRequiredField<PartiallyRequired> // true
type C = HasRequiredField<Optional> // false
Run Code Online (Sandbox Code Playgroud)

typescript conditional-types

4
推荐指数
1
解决办法
1531
查看次数

打字稿检查'any'类型

是否可以any使用打字稿条件语句检查确切的类型?

type IsAny<T> = T extends any ? true : never

type A = IsAny<any> // true
type B = IsAny<number> // never
type C = IsAny<unknown> // never
type D = IsAny<never> // never
Run Code Online (Sandbox Code Playgroud)

typescript

4
推荐指数
2
解决办法
122
查看次数

使用批量删除小于特定大小的文件

有没有办法删除特定文件夹中小于x MB使用批处理文件的所有文件?
我查看了forfiles命令,但看起来它只能删除早于的文件x days.

windows cmd batch-file

2
推荐指数
1
解决办法
6763
查看次数

有没有命令可以检查是否安装了任何防病毒软件?

我正在寻找一个命令来列出Windows 上安装了哪些防病毒软件。如果当前没有安装,我希望它表明这一点

非常感谢

antivirus cmd batch-file

2
推荐指数
1
解决办法
9037
查看次数

打字稿条件参数联合类型

我正在尝试创建一个接受固定数量类型参数的函数,但根据第一个参数顺序参数类型是不同的。

到目前为止,我还没有在 Typescript 文档中找到任何关于此的信息。

例子:

function myFunc(name: 'one' | 'two', data?: 1 | 2) {
  //
}

// Okay
myFunc('one', 1)
myFunc('two', 2)
myFunc('two')

// Should throw an error
myFunc('one', 2)
myFunc('two', 'string')
Run Code Online (Sandbox Code Playgroud)

typescript typescript-typings

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