I frequently see a question in the TypeScript tag where an asker does some logic that semantically should be enough to check that a given type supports a certain operation, but does not satisfy the compiler, and the answer to the question is that they need to use one of the methods the compiler understands (typeof, instanceof, user-defined type guard) explained in the TypeScript handbook.
Glancing through my TypeScript answers, at least half of them are variants on "use a custom type guard" link to playground, link to the documentation.
But strictly speaking, they arguably are not duplicate questions, even though the answer is pretty much the same in every case.
Is there a canonical question for this? Is a canonical even desirable in this case?
{ type: "test" } | { type: "other }
can also be typeguarded with.type === "test"
. And I think there are some more cases, so yeah, having a Q&A to collect all of them sounds like a great idea.