We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
No description provided.
The text was updated successfully, but these errors were encountered:
可选属性的“精确性”:exactOptionalPropertyTypes(TS 4.4+)
exactOptionalPropertyTypes
exactOptionalPropertyTypes 可以让 TS 更精准地区分“确实存在但为 undefined”与“属性根本没定义”。开启后,? 属性就真的表示“此属性可能不存在”,而不是“存在且可以是 undefined”。示例:
undefined
?
{ "compilerOptions": { "exactOptionalPropertyTypes": true } }
interface Test { foo?: string // 要么完全没有 'foo',要么有 'foo' 并且是 string } const t1: Test = {} const t2: Test = { foo: undefined } // Error: foo 不可为 undefined,除非你写 `foo?: string | undefined`
| undefined
Sorry, something went wrong.
No branches or pull requests
No description provided.
The text was updated successfully, but these errors were encountered: