Skip to content

Commit ee52885

Browse files
Yamin YassinYamin Yassin
authored andcommitted
Drop the $FlowFixMe in the web runtime
The default style table cast every entry with $FlowFixMe[incompatible-type]; the types line up now, so the casts are gone. For the debug-style object that stylex.create does not generate, use a small local DebugCompiledStyle type instead of an unclear-type cast. The one suppression left on validateStrictProps stays, with a note on why: typing the argument precisely would block the in-place delete of invalid keys that the function relies on.
1 parent 07b3884 commit ee52885

2 files changed

Lines changed: 8 additions & 51 deletions

File tree

‎packages/react-strict-dom/src/web/modules/createStrictDOMComponent.js‎

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,17 @@
77
* @flow strict
88
*/
99

10-
import type { CompiledStyles } from '@stylexjs/stylex';
11-
import type { ReactDOMStyleProps } from '../../types/renderer.web';
1210
import type { StrictProps } from '../../types/StrictProps';
1311

1412
import * as React from 'react';
1513
import { errorMsg } from '../../shared/logUtils';
1614
import { isPropAllowed } from '../../shared/isPropAllowed';
1715
import { merge } from '../css/merge';
1816

19-
// $FlowFixMe[unclear-type]
17+
// Compiled-style shape for the debug-style object `stylex.create` doesn't generate.
18+
type DebugCompiledStyle = Readonly<{ $$css: true, [string]: string }>;
19+
20+
// $FlowFixMe[unclear-type] precise typing would block the in-place `delete` of invalid keys.
2021
function validateStrictProps(props: any) {
2122
Object.keys(props).forEach((key) => {
2223
const isValid = isPropAllowed(key);
@@ -31,11 +32,9 @@ export function createStrictDOMComponent<T, P extends StrictProps>(
3132
TagName: string,
3233
defaultStyle: StrictProps['style']
3334
): component(ref?: React.RefSetter<T>, ...P) {
34-
// NOTE: `debug-style` is not generated by `stylex.create`
35-
// so it needs a type-cast
36-
const debugStyle: CompiledStyles = {
35+
const debugStyle: DebugCompiledStyle = {
3736
$$css: true,
38-
'debug::name': `html-${TagName}` as $FlowFixMe
37+
'debug::name': `html-${TagName}`
3938
};
4039

4140
component Component(ref?: React.RefSetter<T>, ...props: P) {
@@ -50,8 +49,7 @@ export function createStrictDOMComponent<T, P extends StrictProps>(
5049
hostProps.htmlFor = htmlFor;
5150
}
5251
if (props.role != null) {
53-
// "presentation" synonym has wider browser support
54-
// $FlowFixMe[incompatible-type]
52+
// $FlowFixMe[incompatible-type] "presentation" synonym has wider browser support
5553
hostProps.role = props.role === 'none' ? 'presentation' : props.role;
5654
}
5755
if (TagName === 'button') {
@@ -63,12 +61,7 @@ export function createStrictDOMComponent<T, P extends StrictProps>(
6361
/**
6462
* get host style props
6563
*/
66-
// $FlowFixMe[incompatible-type]
67-
const hostStyleProps: ReactDOMStyleProps = merge([
68-
debugStyle,
69-
defaultStyle,
70-
style
71-
]);
64+
const hostStyleProps = merge([debugStyle, defaultStyle, style]);
7265

7366
/**
7467
* Construct tree

‎packages/react-strict-dom/src/web/runtime.js‎

Lines changed: 0 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -81,88 +81,52 @@ const styles = stylex.create({
8181
}
8282
});
8383

84-
// $FlowFixMe[incompatible-type]
8584
const a: StrictReactDOMPropsStyle = styles.inline;
86-
// $FlowFixMe[incompatible-type]
8785
const article: StrictReactDOMPropsStyle = styles.block;
88-
// $FlowFixMe[incompatible-type]
8986
const aside: StrictReactDOMPropsStyle = styles.block;
90-
// $FlowFixMe[incompatible-type]
9187
const b: StrictReactDOMPropsStyle = styles.inline;
92-
// $FlowFixMe[incompatible-type]
9388
const bdi: StrictReactDOMPropsStyle = styles.inline;
94-
// $FlowFixMe[incompatible-type]
9589
const bdo: StrictReactDOMPropsStyle = styles.inline;
96-
// $FlowFixMe[incompatible-type]
9790
const blockquote: StrictReactDOMPropsStyle = styles.block;
9891
const br: StrictReactDOMPropsStyle = null;
99-
// $FlowFixMe[incompatible-type]
10092
const button: StrictReactDOMPropsStyle = [styles.inlineblock, styles.button];
101-
// $FlowFixMe[incompatible-type]
10293
const code: StrictReactDOMPropsStyle = [styles.inline, styles.codePre];
10394
const del: StrictReactDOMPropsStyle = null;
104-
// $FlowFixMe[incompatible-type]
10595
const div: StrictReactDOMPropsStyle = styles.block;
106-
// $FlowFixMe[incompatible-type]
10796
const em: StrictReactDOMPropsStyle = styles.inline;
108-
// $FlowFixMe[incompatible-type]
10997
const fieldset: StrictReactDOMPropsStyle = styles.block;
110-
// $FlowFixMe[incompatible-type]
11198
const footer: StrictReactDOMPropsStyle = styles.block;
112-
// $FlowFixMe[incompatible-type]
11399
const form: StrictReactDOMPropsStyle = styles.block;
114-
// $FlowFixMe[incompatible-type]
115100
const heading: StrictReactDOMPropsStyle = [styles.block, styles.heading];
116-
// $FlowFixMe[incompatible-type]
117101
const header: StrictReactDOMPropsStyle = styles.block;
118-
// $FlowFixMe[incompatible-type]
119102
const hr: StrictReactDOMPropsStyle = [styles.block, styles.hr];
120-
// $FlowFixMe[incompatible-type]
121103
const i: StrictReactDOMPropsStyle = styles.inline;
122-
// $FlowFixMe[incompatible-type]
123104
const img: StrictReactDOMPropsStyle = styles.img;
124-
// $FlowFixMe[incompatible-type]
125105
const input: StrictReactDOMPropsStyle = [styles.inlineblock, styles.input];
126106
const ins: StrictReactDOMPropsStyle = null;
127107
const kbd: StrictReactDOMPropsStyle = null;
128-
// $FlowFixMe[incompatible-type]
129108
const label: StrictReactDOMPropsStyle = styles.inline;
130-
// $FlowFixMe[incompatible-type]
131109
const li: StrictReactDOMPropsStyle = styles.block;
132-
// $FlowFixMe[incompatible-type]
133110
const main: StrictReactDOMPropsStyle = styles.block;
134-
// $FlowFixMe[incompatible-type]
135111
const mark: StrictReactDOMPropsStyle = styles.inline;
136-
// $FlowFixMe[incompatible-type]
137112
const nav: StrictReactDOMPropsStyle = styles.block;
138-
// $FlowFixMe[incompatible-type]
139113
const ol: StrictReactDOMPropsStyle = [styles.list, styles.block];
140114
const optgroup: StrictReactDOMPropsStyle = null;
141115
const option: StrictReactDOMPropsStyle = null;
142-
// $FlowFixMe[incompatible-type]
143116
const p: StrictReactDOMPropsStyle = styles.block;
144-
// $FlowFixMe[incompatible-type]
145117
const pre: StrictReactDOMPropsStyle = [styles.block, styles.codePre];
146118
const s: StrictReactDOMPropsStyle = null;
147-
// $FlowFixMe[incompatible-type]
148119
const section: StrictReactDOMPropsStyle = styles.block;
149-
// $FlowFixMe[incompatible-type]
150120
const select: StrictReactDOMPropsStyle = styles.inlineblock;
151-
// $FlowFixMe[incompatible-type]
152121
const span: StrictReactDOMPropsStyle = styles.inline;
153-
// $FlowFixMe[incompatible-type]
154122
const strong: StrictReactDOMPropsStyle = [styles.inline, styles.strong];
155-
// $FlowFixMe[incompatible-type]
156123
const sub: StrictReactDOMPropsStyle = styles.inline;
157-
// $FlowFixMe[incompatible-type]
158124
const sup: StrictReactDOMPropsStyle = styles.inline;
159-
// $FlowFixMe[incompatible-type]
160125
const textarea: StrictReactDOMPropsStyle = [
161126
styles.inlineblock,
162127
styles.textarea
163128
];
164129
const u: StrictReactDOMPropsStyle = null;
165-
// $FlowFixMe[incompatible-type]
166130
const ul: StrictReactDOMPropsStyle = [styles.list, styles.block];
167131

168132
export const defaultStyles = {

0 commit comments

Comments
 (0)