Skip to content

Possible regression in 3.9-beta when destructuring from a union including undefined #38110

@shawnmcknight

Description

@shawnmcknight

TypeScript Version: Nightly

Search Terms:
undefined, destructure, destructuring

Code

interface Foo {
  foo1: string
}

let foo: Foo | undefined;
const { foo1 } = foo; // foo1: string

Expected behavior:
As in 3.8, the const { foo1 } = foo; should emit error Property 'foo1' does not exist on type 'Foo | undefined'.(2339)

Actual behavior:
No error emitted. Type of foo1 is inferred as string.

Playground Link:
https://www.typescriptlang.org/play/?ts=Nightly#code/JYOwLgpgTgZghgYwgAgGIHt3IN4ChnIyYCMAXMgM5hSgDmuAvrrgDYRiGbkZYA+yAVxAATCDFARhAblwJ0IKjk7piyBsgC8yqcgD0u5WUrU6QA

Related Issues:
None found

Metadata

Metadata

Assignees

Labels

BugA bug in TypeScript

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions