Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

No error when accessing setter-only properties #58112

Open
MazeChaZer opened this issue Apr 8, 2024 · 2 comments
Open

No error when accessing setter-only properties #58112

MazeChaZer opened this issue Apr 8, 2024 · 2 comments
Labels
In Discussion Not yet reached consensus Suggestion An idea for TypeScript

Comments

@MazeChaZer
Copy link

MazeChaZer commented Apr 8, 2024

πŸ”Ž 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.

@MartinJohns
Copy link
Contributor

Duplicate of #30852, which is marked a duplicate of #21759. See this comment: #30852 (comment)

@andrewbranch andrewbranch added the Duplicate An existing issue was already created label Apr 8, 2024
@DanielRosenwasser
Copy link
Member

Things have changed since those comments. set is encoded into the declaration files (though with some bugs - playground link). We should reconsider this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
In Discussion Not yet reached consensus Suggestion An idea for TypeScript
Projects
None yet
Development

No branches or pull requests

4 participants