Skip to content

No error when accessing setter-only propertiesΒ #58112

Open
@MazeChaZer

Description

@MazeChaZer

πŸ”Ž Search Terms

"setter only", "setter-only"

πŸ•— Version & Regression Information

  • This behavior is present in the current version of TypeScript, 5.4.4

⏯ Playground Link

https://www.typescriptlang.org/play?#code/MYGwhgzhAEBiD29oG8BQ0PQgUwC7QCMwAnACiIC8AuLXYgSwDsBzAShWgF9VvVh5GEfADNE0ALzRG2AO5xEpVgG4+AodABuYEAFdsNIQxYToo+ADoixJdAD0t6ABUAFvRiQI9ZowC22RvgQzvA6IAAmUvD4BNjQ2iDwMthhADSmiJYk0DL0ICBxIDJgAJ4wMdA6jGHYwkzJAIRAA

πŸ’» Code

class Foo {
    set bar(baz: string) { }
}

const foo = new Foo();
const value: string = foo.bar; // This assignment should not be allowed, foo.bar will always be undefined!

πŸ™ Actual behavior

There is no error reported during type-checking.

πŸ™‚ Expected behavior

The type-checking should report an error for the assignment in the last line as foo.bar will always be undefined.

Additional information about the issue

#21759 is related, but that issue proposes a whole new language feature, this issue is solely about the lack of a type error.

Metadata

Metadata

Assignees

No one assigned

    Labels

    In DiscussionNot yet reached consensusSuggestionAn idea for TypeScript

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions