Skip to content

Readonly optional properties break type-checkingΒ #50669

@JSMonk

Description

@JSMonk

Bug Report

πŸ•— Version & Regression Information

Found in TS v4.8.2.
This is the behavior in every version I tried, and I reviewed the FAQ for entries about

⏯ Playground Link

Playground link with relevant code

πŸ’» Code

// Original Case
declare function foo(obj: { readonly constructor?: any }): void

foo(Object) // Error!!!

declare function bar(obj: { readonly constructor: any }): void;

bar(Object) // OK

πŸ™ Actual behavior

ObjectConstructor is not a subtype of { readonly constructor?: any }, at the same time it is a subtype of a type { readonly constructor: any }

πŸ™‚ Expected behavior

In the code above, I expect that type ObjectConstructor will be a subtype of the object type { readonly constructor?: any }, because the object use constructor in a covariant way (I can't delete the property inside the function.)

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugA bug in TypeScript

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions