I am using TypeScript version 2.3.4. I want to write a function that takes an object that must have the specified fields. But this object should not contain any other fields. How can I achieve this?
Now this only works if I define an inline object. But if I use another object with additional fields, this will allow the compiler. Which is completely wrong.
Example:
function foo(arg: { a: string }) {
The same code can be called with interfaces, classes, type declarations - this is the same problem.
Now I need to extract the fields from the object manually to make sure that there are no additional fields. But I can not extend this solution to ~ 1000 functions (I really need it) throughout the code - this is too dirty. I am creating an API wrapper and I need to make sure that no additional or incorrect fields are added to the server.
Harry burns
source share