Note that you might find that using instanceof will be a bit more straight forward in TypeScript since it will automatically narrow the type, but doing this is very slow compared to @Evgeni_Popov’s solution.
// don't do this as it is very slow
if (pickedMesh instanceof InstancedMesh) {
const sourceMesh = pickedMesh.sourceMesh;
}