TS2687

error TS2687: All declarations of ‘status’ must have identical modifiers. lib.dom.d.ts(11620, 14): ‘status‘ was also declared here.

Broken Code ❌

1
2
3
4
interface Response {
data?: string;
status: StreamStatus;
}

Fixed Code ✔️

In the error above, a Response is declared which should be merged (using declaration merging) with the Response interface of the “dom” library which is set in “lib” within the “tsconfig.json” file. When merging with an existing declaration, the property types of the first declaration must be matched because you can only add additional properties when using declaration merging. The same rules applies to modifiers. Because “status” has a readonly modifier in the existing Response interface, we must declare the same in our own interface extension:

1
2
3
4
interface Response {
data?: string;
readonly status: number;
}