There's no nice built-in functionality to do this, as was mentioned in the comments. There are a few approaches, but none of them are great.
Write the checks manually
As you mentioned in your question, you can just write everything manually. I'd do this if you don't have very many interfaces, but it quickly becomes impractical.
Automatically generate boilerplate
One approach is automatically generating the boilerplate. This is less boring than writing it yourself, but still has a lot of problems (do you check in the boilerplate? do you include it in some build step?)
This would take a while to write yourself, but there are npm libraries to do this for you. I haven't used any so I won't make recommendations, but I'm sure you could find some.
Write the interfaces some other way
Instead of using regular typescript interfaces, you could define them some other way to facilitate automatic checking. There are also many libraries that do this, though again I'll make no recommendations.
It's also practical to do this yourself, if your use case isn't too complicated.
I've put together a simple example that will check one level deep for simple types in an object. It won't work for every case, so if you decide to take this approach yourself make sure to design it to work for the cases you care about.
class Checker<T extends {}> {
constructor(public readonly example: T) {}
public check(other: {}): other is T {
const exampleKeys = new Set(Object.keys(this.example));
const otherKeys = new Set(Object.keys(other));
if (exampleKeys.size !== otherKeys.size) { return false; }
for (const key of exampleKeys) {
if (!otherKeys.has(key)) { return false; }
if (typeof (other as any)[key] !== typeof (this.example as any)[key]) { return false; }
}
return true;
}
}
const bChecker = new Checker({
cat: true,
name: "",
})
type B = typeof bChecker.example;
const something: {} = {
cat: false,
name: "Spot",
}
if (bChecker.check(something)) {
const b: B = something;
}
Overall, there's no perfect approach. However, there are alternatives to writing a bunch of boilerplate yourself.