While trying to stub out a class for testing, I encountered errors indicating that private members are missing. This is unexpected as TypeScript should only concern itself with public members accessible from the outside.
The error states: 'Property 'a' is missing in type '{ b: () => number; }' but required in type 'MyClass'.(2741)'
class MyClass {
private a() {
return 1
}
public b() {
return 2
}
}
const test: MyClass = {
b: () => 2
}
Click here for a Typescript Playground implementation.
I am puzzled by why TypeScript demands private member implementations in this scenario.
What workaround would you suggest for this?