'document' is a typed dict, which mypy does not seem to allow here
Migrated from D8128 (view on Phabricator)