Skip to content

Instantly share code, notes, and snippets.

@ReVoid
Created November 25, 2024 17:37
Show Gist options
  • Save ReVoid/926469050033f47d228b97eef9ad9405 to your computer and use it in GitHub Desktop.
Save ReVoid/926469050033f47d228b97eef9ad9405 to your computer and use it in GitHub Desktop.
Optional vs undefined
// 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