Microsoft/TypeScript

Error when destructuring deep nested object with literal initializers as fallback

Open

#54.237 geöffnet am 13. Mai 2023

Auf GitHub ansehen
 (2 Kommentare) (0 Reaktionen) (0 zugewiesene Personen)TypeScript (6.726 Forks)batch import
BugDomain: check: Type InferenceHelp Wanted

Repository-Metriken

Stars
 (48.455 Stars)
PR-Merge-Metriken
 (Durchschn. Merge 6T 17h) (9 gemergte PRs in 30 T)

Beschreibung

Bug Report

🔎 Search Terms

  • destructuring
  • nested
  • literal initializer

🕗 Version & Regression Information

⏯ Playground Link

Playground link with relevant code

💻 Code

interface Props {
  innerObject?: {
    innerObject2?: {
      name?: string;
      email?: string;
    }
  };
}

// won't let name and email default to undefined
// Initializer provides no value for this binding element and the binding element has no default value. 
export const nestedDestructure1 = (props: Props) => {
  const {
    innerObject: {
       innerObject2: { name, email } = {}
    } = {}
  } = props;
  console.log(name, email);
};

🙁 Actual behavior

Initializer provides no value for this binding element and the binding element has no default value.(2525)

🙂 Expected behavior

name and email default to undefined and has type string | undefined

Contributor Guide