Skip to content

Error is not showing on comparing when interface has optional variables #36602

Closed
@andropov-sergej

Description

@andropov-sergej

Code

interface A {
    id?: number;
}
const a:A = {
    id: 5
};
const testA: boolean = (a === 1); //works, but why?


interface B {
    id: number;
}
const b:B = {
    id: 5
};
const testB: boolean = (b === 1); //compiler error -> expected that also on A

Expected behavior:
An error on the compare line.

Actual behavior:
No error

Playground Link:
https://www.typescriptlang.org/play/?ssl=1&ssc=1&pln=18&pc=1#code/JYOwLgpgTgZghgYwgAgILIN4Chm+cAEwH4AuZEAVwFsAjaAbiwF8sEB7EAZzGThPQC8mHHkJkArM0bsuPSN1RkabNgBsIcEMiEAKONoFCAjAEp6yAPQWA7mygBrTgBpkNCj2sALAJ5Es-0EhYRBQAIWE8fAIySloGZlYOblcScKFsSLFkSSZpJLkIblClFXVNbWQdGgNjM0sLdioAB2B1KGRoKDtkAFoAPg6ADyaIBEgCZDBPOB44VU42ZA40fyA

Related Issues:

Metadata

Metadata

Assignees

No one assigned

    Labels

    QuestionAn issue which isn't directly actionable in code

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions