Is there a way to ensure at compile time that an inferred type matches another interface without losing the inferred type?
Say with have this simple interface and an object which implements it:
interface Person {
name: string;
}
const bob = {
name: "Bob"
}
type Bob = typeof bob;
I want to keep the inferred type Bob which is more specific than Person, but I also want to make sure it matches Person.
const bob: Bob = { // this kills the implicit type
name: "bob"
}
----
const bob = {} // but I want this to fail, because `name` is missing
----
const bob = {
name: "Bob",
age: 30, // I want this to fail too, because it doesn't correspond to `Person`
}