我不是的意思是question mark syntax,例如,我在问-?
:
type Required<T> =
T extends object
? { [P in keyof T]-?: NonNullable<T[P]>; } // <---------- "-?" here
: T;
通过this 2018 GitHub comment。我无法在TypeScript手册的advanced types和utility types章节中找到此语法。
-?
如上所述,仍在TypeScript 3.8中编译,并且似乎是?
的相反,即是否需要密钥?等于Required
吗?如果不是,则此语法称为什么,我在哪里可以了解更多?
您基本上是对的:它从Required
中删除了可选的属性修饰符?
。它在TypeScript 2.8中作为mapped type的一部分引入。它不是improvements to control over mapped type modifiers (see this link for the docs you want)实用程序类型的[[identical,但是Required
是Required
,没有它就无法存在。
好的,希望能有所帮助;祝你好运!