TS2339

error TS2339: Property ‘name‘ does not exist on type ‘Function‘.

Bad Code ❌

1
2
3
4
5
6
export class RecordNotFoundError extends Error {
constructor(public message: string) {
super(message);
this.name = this.constructor.name;
}
}

Fixed Code ✔️

1
2
3
4
5
6
export class RecordNotFoundError extends Error {
constructor(public message: string) {
super(message);
this.name = (<any>this).constructor.name;
}
}