Skip to content

Checking whether a property is defined or not using the dot notation should not be an error.Β #42167

Closed
@biswasxx08

Description

@biswasxx08

Bug Report

πŸ”Ž Search Terms

Property Definition Check
Property Undefined Check

πŸ•— Version & Regression Information

  • This is the behavior in every version I tried.

⏯ Playground Link

Playground link with relevant code

πŸ’» Code

export type Point2D = { x: number, y: number };
export type Point3D = Point2D & { z: number };
export type Point = Point2D | Point3D;

export function draw(p: Point) {
  // This check should not be an error!
  if (p.z != undefined) { console.log("Point3D"); }
  else { console.log("Point2D"); }
}

let p1: Point = { x: 1, y: 2, z: 3 };
draw(p1);



// We can quickly address your report if:
//  - The code sample is short. Nearly all TypeScript bugs can be demonstrated in 20-30 lines of code!
//  - It doesn't use external libraries. These are often issues with the type definitions rather than TypeScript bugs.
//  - The incorrectness of the behavior is readily apparent from reading the sample.
// Reports are slower to investigate if:
//  - We have to pare too much extraneous code.
//  - We have to clone a large repo and validate that the problem isn't elsewhere.
//  - The sample is confusing or doesn't clearly demonstrate what's wrong.

πŸ™ Actual behavior

Property 'z' does not exist on type 'Point'.
  Property 'z' does not exist on type 'Point2D'.(2339)

πŸ™‚ Expected behavior

Checking if the property is defined should not be an error.

Metadata

Metadata

Assignees

No one assigned

    Labels

    DuplicateAn existing issue was already created

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions