From 141a1e1ae668454bb989eb738d159f0ca850295b Mon Sep 17 00:00:00 2001 From: Chris Bobbe Date: Tue, 27 Jul 2021 14:08:43 -0400 Subject: [PATCH] styles types: Set type signature of default export in a way Flow can track. Following Greg's recommendation at https://chat.zulip.org/#narrow/stream/243-mobile-team/topic/Flow.20types-first/near/1237936. This will help move us along toward Flow's new "Types-First" mode; switching entirely is #4907. --- src/styles/index.js | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/styles/index.js b/src/styles/index.js index f818b790259..208d173a9ff 100644 --- a/src/styles/index.js +++ b/src/styles/index.js @@ -43,9 +43,21 @@ export function createStyleSheet<+S: ____Styles_Internal>(obj: S): S { return Object.freeze(obj); } -export default createStyleSheet({ +// By `Object.freeze`, we really mean `createStyleSheet`. But that's too +// much for Flow in types-first mode, and it can't tell the exported +// object's type on a quick skim. But apparently it has no problem if we +// just do an `Object.freeze` directly. So, do that, and get +// `createStyleSheet` to type-check the contents of `styles` separately, in +// a trivial bit of code below. +const styles = Object.freeze({ ...composeBoxStyles, ...miscStyles, ...navStyles, ...utilityStyles, }); + +// Check the contents of `styles` (see comment above). +// eslint-disable-next-line no-unused-expressions +() => createStyleSheet(styles); + +export default styles;