Microsoft/TypeScript
GitHub ã§èŠãError when destructuring deep nested object with literal initializers as fallback
Open
#54,237 opened on 2023幎5æ13æ¥
BugDomain: check: Type InferenceHelp Wanted
Repository metrics
- Stars
- Â (48,455 stars)
- PR merge metrics
-  (å¹³åããŒãž 6d 17h) (30d ã§ 9 merged PRs)
説æ
Bug Report
ð Search Terms
- destructuring
- nested
- literal initializer
ð Version & Regression Information
- This is the behavior in every version I tried, and I reviewed the FAQ for entries about https://github.com/microsoft/TypeScript/issues/26235
⯠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