TS1095

error TS1095: A ‘set’ accessor cannot have a return type annotation.

Broken Code ❌

1
2
3
4
5
6
7
8
9
10
11
export class Person {
private myName: string = 'unknown';

get name(): string {
return this.myName;
}

set name(newName: string): void {
this.myName = newName;
}
}

Fixed Code ✔️

You have to remove the return type from the “set” accessor:

1
2
3
4
5
6
7
8
9
10
11
export class Person {
private myName: string = 'unknown';

get name(): string {
return this.myName;
}

set name(newName: string) {
this.myName = newName;
}
}