Skip to content

Add rule to detect reads of write-only-properties #372

@ajafff

Description

@ajafff

TypeScript doesn't have a concept to support write-only properties in the same way it supports readonly properties. It treats properties with a setter as read/writable.

This can lead to bugs if you try to read the value of the property as it will always yield undefined but TypeScript infers another type.

const obj = new class {
  set prop(v: any) {}
}
console.log(obj.prop); // error here
obj.prop++; // error here, calls setter with NaN

TypeScript issue: microsoft/TypeScript#11596

TBD: how to handle unions of different class instances where the accessed property is write-only in one instance.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions