Closed
Description
Search Terms
- map access modifiers
- access modifier map
- type helper access modifier
Suggestion
We have a way to modify the properties of an interface, and make its properties readonly, mutable, optional or required.
I would like a way to modify the access modifiers of an interface.
I would like a way to get an interface with only a certain access modifier.
Use Cases
This would be useful for mocking objects with class as interfaces without losing a given interface (most useful the public interface).
Examples
// service-a.ts
class ServiceA {
private someMethodA() {
// Does something cool, trust me.
}
public someMethodB() {
// Does something cool as well.
}
}
// consumer-of-the-service.ts
const ServiceAMock: PublicShape<ServiceA> = { // Using a type mapper, only public properties are required in the object, as private properties aren't needed if we are mocking the public implementation.
someMethodB() {
return mockValue;
}
}
Checklist
My suggestion meets these guidelines:
- This wouldn't be a breaking change in existing TypeScript/JavaScript code
- This wouldn't change the runtime behavior of existing JavaScript code
- This could be implemented without emitting different JS based on the types of the expressions
- This isn't a runtime feature (e.g. library functionality, non-ECMAScript syntax with JavaScript output, etc.)
- This feature would agree with the rest of TypeScript's Design Goals.