Created
November 25, 2024 17:37
-
-
Save ReVoid/926469050033f47d228b97eef9ad9405 to your computer and use it in GitHub Desktop.
Optional vs undefined
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Do these syntaxes produce the same result? | |
let x: { foo?: string }; | |
let y: { foo: string | undefined }; | |
x = {}; // ✅ The value can be omitted entirely, even `undefined` | |
y = {}; // ❌ The value must be explicitly provided, even if it is `undefined` | |
y = { foo: undefined }; // ✅ `undefined` is explicitly assigned |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment