Skip to content

Commit c5377cd

Browse files
authoredAug 31, 2023
Update cssmap types (#1499)
* Update cssmap types * Replace readonly * Add changeset
1 parent 4a2174c commit c5377cd

29 files changed

+47
-36
lines changed
 

‎.changeset/six-apples-invite.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@compiled/react': patch
3+
---
4+
5+
Ensure that the return types of `css` and `cssMap` are readonly.

‎package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@
9090
"eslint-plugin-react": "^7.32.2",
9191
"eslint-plugin-react-hooks": "^4.6.0",
9292
"flow-bin": "^0.183.0",
93-
"flowgen": "^1.20.1",
93+
"flowgen": "^1.21.0",
9494
"husky": "^4.3.8",
9595
"jest": "^29.4.3",
9696
"jest-environment-jsdom": "^29.4.3",

‎packages/jest/src/index.js.flow

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/**
22
* Flowtype definitions for index
33
* Generated by Flowgen from a Typescript Definition
4-
* Flowgen v1.20.1
4+
* Flowgen v1.21.0
55
* @flow
66
*/
77
import type { MatchFilter } from './types';

‎packages/jest/src/matchers.js.flow

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/**
22
* Flowtype definitions for matchers
33
* Generated by Flowgen from a Typescript Definition
4-
* Flowgen v1.20.1
4+
* Flowgen v1.21.0
55
* @flow
66
*/
77
import type { MatchFilter } from './types';

‎packages/jest/src/types.js.flow

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/**
22
* Flowtype definitions for types
33
* Generated by Flowgen from a Typescript Definition
4-
* Flowgen v1.20.1
4+
* Flowgen v1.21.0
55
* @flow
66
*/
77
import type { Pseudos } from 'csstype';

‎packages/react/src/class-names/index.js.flow

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/**
22
* Flowtype definitions for index
33
* Generated by Flowgen from a Typescript Definition
4-
* Flowgen v1.20.1
4+
* Flowgen v1.21.0
55
* @flow
66
*/
77
import type { Node } from 'react';

‎packages/react/src/css-map/index.js.flow

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/**
22
* Flowtype definitions for index
33
* Generated by Flowgen from a Typescript Definition
4-
* Flowgen v1.20.1
4+
* Flowgen v1.21.0
55
* @flow
66
*/
77
import type { CSSProps, CssObject } from '../types';
@@ -20,6 +20,7 @@ import type { CSSProps, CssObject } from '../types';
2020
* <Component borderStyle="solid" />
2121
* ```
2222
*/
23+
declare type returnType<T: string, P> = { [key: T]: CSSProps<P> };
2324
declare export default function cssMap<T: string, TProps>(_styles: {
2425
[key: T]: CssObject<TProps> | CssObject<TProps>[],
25-
}): { [key: T]: CSSProps<TProps> };
26+
}): $ReadOnly<returnType<T, TProps>>;

‎packages/react/src/css-map/index.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,10 @@ import { createSetupError } from '../utils/error';
1818
* <Component borderStyle="solid" />
1919
* ```
2020
*/
21+
type returnType<T extends string, P> = Record<T, CSSProps<P>>;
22+
2123
export default function cssMap<T extends string, TProps = unknown>(
2224
_styles: Record<T, CssObject<TProps> | CssObject<TProps>[]>
23-
): Record<T, CSSProps<TProps>> {
25+
): Readonly<returnType<T, TProps>> {
2426
throw createSetupError();
2527
}

‎packages/react/src/css/index.js.flow

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/**
22
* Flowtype definitions for index
33
* Generated by Flowgen from a Typescript Definition
4-
* Flowgen v1.20.1
4+
* Flowgen v1.21.0
55
* @flow
66
*/
77
import type { CSSProps, CssObject, CssFunction } from '../types';

‎packages/react/src/index.js.flow

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/**
22
* Flowtype definitions for index
33
* Generated by Flowgen from a Typescript Definition
4-
* Flowgen v1.20.1
4+
* Flowgen v1.21.0
55
* @flow
66
*/
77
import type { CssFunction, CSSProps, CssType } from './types';

‎packages/react/src/keyframes/index.js.flow

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/**
22
* Flowtype definitions for index
33
* Generated by Flowgen from a Typescript Definition
4-
* Flowgen v1.20.1
4+
* Flowgen v1.21.0
55
* @flow
66
*/
77
import type { BasicTemplateInterpolations, CSSProps } from '../types';

‎packages/react/src/runtime.js.flow

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/**
22
* Flowtype definitions for runtime
33
* Generated by Flowgen from a Typescript Definition
4-
* Flowgen v1.20.1
4+
* Flowgen v1.21.0
55
* @flow
66
*/
77
declare export { CC, CS, ax, ac, clearAcCache, ix } from './runtime/index';

‎packages/react/src/runtime/ac.js.flow

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/**
22
* Flowtype definitions for ac
33
* Generated by Flowgen from a Typescript Definition
4-
* Flowgen v1.20.1
4+
* Flowgen v1.21.0
55
* @flow
66
*/
77
/**

‎packages/react/src/runtime/ax.js.flow

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/**
22
* Flowtype definitions for ax
33
* Generated by Flowgen from a Typescript Definition
4-
* Flowgen v1.20.1
4+
* Flowgen v1.21.0
55
* @flow
66
*/
77
/**

‎packages/react/src/runtime/cache.js.flow

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/**
22
* Flowtype definitions for cache
33
* Generated by Flowgen from a Typescript Definition
4-
* Flowgen v1.20.1
4+
* Flowgen v1.21.0
55
* @flow
66
*/
77
/**

‎packages/react/src/runtime/css-custom-property.js.flow

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/**
22
* Flowtype definitions for css-custom-property
33
* Generated by Flowgen from a Typescript Definition
4-
* Flowgen v1.20.1
4+
* Flowgen v1.21.0
55
* @flow
66
*/
77
/**
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/**
22
* Flowtype definitions for dev-warnings
33
* Generated by Flowgen from a Typescript Definition
4-
* Flowgen v1.20.1
4+
* Flowgen v1.21.0
55
* @flow
66
*/
77
declare export var analyzeCssInDev: (sheet: string) => void;

‎packages/react/src/runtime/index.js.flow

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/**
22
* Flowtype definitions for index
33
* Generated by Flowgen from a Typescript Definition
4-
* Flowgen v1.20.1
4+
* Flowgen v1.21.0
55
* @flow
66
*/
77
declare export { default as CS } from './style';

‎packages/react/src/runtime/is-server-environment.js.flow

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/**
22
* Flowtype definitions for is-server-environment
33
* Generated by Flowgen from a Typescript Definition
4-
* Flowgen v1.20.1
4+
* Flowgen v1.21.0
55
* @flow
66
*/
77
/**

‎packages/react/src/runtime/sheet.js.flow

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/**
22
* Flowtype definitions for sheet
33
* Generated by Flowgen from a Typescript Definition
4-
* Flowgen v1.20.1
4+
* Flowgen v1.21.0
55
* @flow
66
*/
77
import type { Bucket, StyleSheetOpts } from './types';

‎packages/react/src/runtime/style-cache.js.flow

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/**
22
* Flowtype definitions for style-cache
33
* Generated by Flowgen from a Typescript Definition
4-
* Flowgen v1.20.1
4+
* Flowgen v1.21.0
55
* @flow
66
*/
77
import type { ProviderComponent, UseCacheHook } from './types';

‎packages/react/src/runtime/style.js.flow

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/**
22
* Flowtype definitions for style
33
* Generated by Flowgen from a Typescript Definition
4-
* Flowgen v1.20.1
4+
* Flowgen v1.21.0
55
* @flow
66
*/
77
import type { StyleSheetOpts } from './types';

‎packages/react/src/runtime/types.js.flow

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/**
22
* Flowtype definitions for types
33
* Generated by Flowgen from a Typescript Definition
4-
* Flowgen v1.20.1
4+
* Flowgen v1.21.0
55
* @flow
66
*/
77
export interface StyleSheetOpts {

‎packages/react/src/styled/index.js.flow

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/**
22
* Flowtype definitions for index
33
* Generated by Flowgen from a Typescript Definition
4-
* Flowgen v1.20.1
4+
* Flowgen v1.21.0
55
* @flow
66
*/
77
import type { ComponentType } from 'react';

‎packages/react/src/types.js.flow

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/**
22
* Flowtype definitions for types
33
* Generated by Flowgen from a Typescript Definition
4-
* Flowgen v1.20.1
4+
* Flowgen v1.21.0
55
* @flow
66
*/
77
import * as CSS from 'csstype';
@@ -19,11 +19,11 @@ export type CssType<TProps> = CssObject<TProps> | FunctionInterpolation<TProps>
1919
/**
2020
* These are all the CSS props that will exist.
2121
*/
22-
export type CSSProps<TProps> = CSS.Properties<CssFunction<TProps>>;
23-
export type CssObject<TProps> = {
22+
export type CSSProps<TProps> = $ReadOnly<CSS.Properties<CssFunction<TProps>>>;
23+
export type CssObject<TProps> = $ReadOnly<{
2424
...CSSProps<TProps>,
2525
[key: string]: CssFunction<TProps>,
26-
};
26+
}>;
2727
export type CssFunction<TProps = mixed> =
2828
| CssType<TProps>
2929
| BasicTemplateInterpolations

‎packages/react/src/types.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,11 @@ export type CssType<TProps> =
2121
/**
2222
* These are all the CSS props that will exist.
2323
*/
24-
export type CSSProps<TProps> = CSS.Properties<CssFunction<TProps>>;
24+
export type CSSProps<TProps> = Readonly<CSS.Properties<CssFunction<TProps>>>;
2525

26-
export type CssObject<TProps> = {
26+
export type CssObject<TProps> = Readonly<{
2727
[key: string]: CssFunction<TProps>;
28-
};
28+
}>;
2929

3030
// CSS inside of a CSS expression
3131
export type CssFunction<TProps = unknown> =
+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/**
22
* Flowtype definitions for error
33
* Generated by Flowgen from a Typescript Definition
4-
* Flowgen v1.20.1
4+
* Flowgen v1.21.0
55
* @flow
66
*/
77
declare export var createSetupError: () => Error;

‎scripts/flow-types.sh

+3
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,9 @@ generate() {
4646
# Use readonly array to handle flow strict mode
4747
sed -i.bak -E 's/css: CssObject<TProps> \| CssObject<TProps>\[\],/css: CssObject<TProps> \| \$ReadOnlyArray<CssObject<TProps>>,/g' "$file" && rm "$file.bak"
4848

49+
# Replace Readonly with $ReadOnly
50+
sed -i.bak -E 's/Readonly</$ReadOnly</g' "$file" && rm "$file.bak"
51+
4952
# Rename JSX.IntrinsicElements to existing flow type
5053
sed -i.bak -E 's/JSX.IntrinsicElements/$JSXIntrinsics/g' "$file" && rm "$file.bak"
5154

‎yarn.lock

+4-4
Original file line numberDiff line numberDiff line change
@@ -8965,10 +8965,10 @@ flow-parser@0.*:
89658965
resolved "https://registry.yarnpkg.com/flow-parser/-/flow-parser-0.149.0.tgz#6e5749ad832ba211968429accdb6a3858706e4f8"
89668966
integrity sha512-ruUVkZuM9oFQjhSsLO/OJYRYpGnuXJpTnIZmgzna6DyLFb3CLpeO27oJbWyeXaa830hmKf0JRzpcdFsFS8lmpg==
89678967

8968-
flowgen@^1.20.1:
8969-
version "1.20.1"
8970-
resolved "https://registry.yarnpkg.com/flowgen/-/flowgen-1.20.1.tgz#336871d59a36980fbe2c3de553bd558f06a46e24"
8971-
integrity sha512-Wus3KAhsOF7CiZGkBKZawf0AJXe06Wot6UGQt7h9QS6MBtBkFgG30wTAgpy1byA3FKYb059vO341XtN8LUhenQ==
8968+
flowgen@^1.21.0:
8969+
version "1.21.0"
8970+
resolved "https://registry.yarnpkg.com/flowgen/-/flowgen-1.21.0.tgz#f7ecb693892c4bd069492dbf77db561bbb451aa9"
8971+
integrity sha512-pFNFFyMLRmW6njhOIm5TrbGUDTv64aujmys2KrkRE2NYD8sXwJUyicQRwU5SPRBRJnFSD/FNlnHo2NnHI5eJSw==
89728972
dependencies:
89738973
"@babel/code-frame" "^7.16.7"
89748974
"@babel/highlight" "^7.16.7"

0 commit comments

Comments
 (0)
Please sign in to comment.