@compiled/react 0.16.3 → 0.16.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -9,7 +9,9 @@ type EnforceSchema<TObject> = {
9
9
  type PickObjects<TObject> = {
10
10
  [P in keyof TObject]: TObject[P] extends Record<string, unknown> ? TObject[P] : never;
11
11
  };
12
- interface CompiledAPI<TSchema> {
12
+ type CSSStyles<TSchema extends CompiledSchema> = StrictCSSProperties & PseudosDeclarations & EnforceSchema<TSchema>;
13
+ type CSSMapStyles<TSchema extends CompiledSchema> = Record<string, CSSStyles<TSchema>>;
14
+ interface CompiledAPI<TSchema extends CompiledSchema> {
13
15
  /**
14
16
  * ## CSS
15
17
  *
@@ -25,7 +27,7 @@ interface CompiledAPI<TSchema> {
25
27
  * <div css={redText} />
26
28
  * ```
27
29
  */
28
- css(styles: StrictCSSProperties & PseudosDeclarations & EnforceSchema<TSchema>): StrictCSSProperties;
30
+ css(styles: CSSStyles<TSchema>): StrictCSSProperties;
29
31
  /**
30
32
  * ## CSS Map
31
33
  *
@@ -42,8 +44,8 @@ interface CompiledAPI<TSchema> {
42
44
  * <div css={styles.solid} />
43
45
  * ```
44
46
  */
45
- cssMap<TStyles extends Record<string, StrictCSSProperties & PseudosDeclarations & EnforceSchema<TSchema>>>(styles: TStyles): {
46
- readonly [P in keyof TStyles]: CompiledStyles<TStyles[P]>;
47
+ cssMap<TStylesMap extends CSSMapStyles<TSchema>>(styles: CSSMapStyles<TSchema>): {
48
+ readonly [P in keyof TStylesMap]: CompiledStyles<TStylesMap[P]>;
47
49
  };
48
50
  /**
49
51
  * ## CX
@@ -1,4 +1,4 @@
1
- import { createSetupError } from '../utils/error';
1
+ import { createStrictSetupError } from '../utils/error';
2
2
  import { cx } from '../xcss-prop';
3
3
  /**
4
4
  * ## Create Strict API
@@ -51,14 +51,14 @@ import { cx } from '../xcss-prop';
51
51
  export function createStrictAPI() {
52
52
  return {
53
53
  css() {
54
- throw createSetupError();
54
+ throw createStrictSetupError();
55
55
  },
56
56
  cssMap() {
57
- throw createSetupError();
57
+ throw createStrictSetupError();
58
58
  },
59
59
  cx,
60
60
  XCSSProp() {
61
- throw createSetupError();
61
+ throw createStrictSetupError();
62
62
  },
63
63
  };
64
64
  }
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/create-strict-api/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAClD,OAAO,EAAuB,EAAE,EAA0B,MAAM,cAAc,CAAC;AA+J/E;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+CG;AACH,MAAM,UAAU,eAAe;IAC7B,OAAO;QACL,GAAG;YACD,MAAM,gBAAgB,EAAE,CAAC;QAC3B,CAAC;QACD,MAAM;YACJ,MAAM,gBAAgB,EAAE,CAAC;QAC3B,CAAC;QACD,EAAE;QACF,QAAQ;YACN,MAAM,gBAAgB,EAAE,CAAC;QAC3B,CAAC;KACF,CAAC;AACJ,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/create-strict-api/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,sBAAsB,EAAE,MAAM,gBAAgB,CAAC;AACxD,OAAO,EAAuB,EAAE,EAA0B,MAAM,cAAc,CAAC;AA+J/E;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+CG;AACH,MAAM,UAAU,eAAe;IAC7B,OAAO;QACL,GAAG;YACD,MAAM,sBAAsB,EAAE,CAAC;QACjC,CAAC;QACD,MAAM;YACJ,MAAM,sBAAsB,EAAE,CAAC;QACjC,CAAC;QACD,EAAE;QACF,QAAQ;YACN,MAAM,sBAAsB,EAAE,CAAC;QACjC,CAAC;KACF,CAAC;AACJ,CAAC"}
@@ -1 +1,2 @@
1
1
  export declare const createSetupError: () => Error;
2
+ export declare const createStrictSetupError: () => Error;
@@ -17,4 +17,23 @@ export const createSetupError = () => {
17
17
  Good luck!
18
18
  `);
19
19
  };
20
+ export const createStrictSetupError = () => {
21
+ return new Error(`
22
+ ██████╗ ██████╗ ███╗ ███╗██████╗ ██╗██╗ ███████╗██████╗
23
+ ██╔════╝██╔═══██╗████╗ ████║██╔══██╗██║██║ ██╔════╝██╔══██╗
24
+ ██║ ██║ ██║██╔████╔██║██████╔╝██║██║ █████╗ ██║ ██║
25
+ ██║ ██║ ██║██║╚██╔╝██║██╔═══╝ ██║██║ ██╔══╝ ██║ ██║
26
+ ╚██████╗╚██████╔╝██║ ╚═╝ ██║██║ ██║███████╗███████╗██████╔╝
27
+ ╚═════╝ ╚═════╝ ╚═╝ ╚═╝╚═╝ ╚═╝╚══════╝╚══════╝╚═════╝
28
+
29
+ @compiled/react
30
+
31
+ Code was executed when it shouldn't have. To resolve make sure to:
32
+
33
+ 1. Set up Compiled.
34
+ 2. Configure importSources in your Compiled config to point to the module that exports the output of createStrictAPI().
35
+
36
+ For more information visit https://compiledcssinjs.com/docs/installation and follow the instructions.
37
+ `);
38
+ };
20
39
  //# sourceMappingURL=error.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"error.js","sourceRoot":"","sources":["../../../src/utils/error.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,gBAAgB,GAAG,GAAU,EAAE;IAC1C,OAAO,IAAI,KAAK,CAAC;;;;;;;;;;;;;;;;CAgBlB,CAAC,CAAC;AACH,CAAC,CAAC"}
1
+ {"version":3,"file":"error.js","sourceRoot":"","sources":["../../../src/utils/error.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,gBAAgB,GAAG,GAAU,EAAE;IAC1C,OAAO,IAAI,KAAK,CAAC;;;;;;;;;;;;;;;;CAgBlB,CAAC,CAAC;AACH,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,sBAAsB,GAAG,GAAU,EAAE;IAChD,OAAO,IAAI,KAAK,CAAC;;;;;;;;;;;;;;;;CAgBlB,CAAC,CAAC;AACH,CAAC,CAAC"}
@@ -9,7 +9,9 @@ type EnforceSchema<TObject> = {
9
9
  type PickObjects<TObject> = {
10
10
  [P in keyof TObject]: TObject[P] extends Record<string, unknown> ? TObject[P] : never;
11
11
  };
12
- interface CompiledAPI<TSchema> {
12
+ type CSSStyles<TSchema extends CompiledSchema> = StrictCSSProperties & PseudosDeclarations & EnforceSchema<TSchema>;
13
+ type CSSMapStyles<TSchema extends CompiledSchema> = Record<string, CSSStyles<TSchema>>;
14
+ interface CompiledAPI<TSchema extends CompiledSchema> {
13
15
  /**
14
16
  * ## CSS
15
17
  *
@@ -25,7 +27,7 @@ interface CompiledAPI<TSchema> {
25
27
  * <div css={redText} />
26
28
  * ```
27
29
  */
28
- css(styles: StrictCSSProperties & PseudosDeclarations & EnforceSchema<TSchema>): StrictCSSProperties;
30
+ css(styles: CSSStyles<TSchema>): StrictCSSProperties;
29
31
  /**
30
32
  * ## CSS Map
31
33
  *
@@ -42,8 +44,8 @@ interface CompiledAPI<TSchema> {
42
44
  * <div css={styles.solid} />
43
45
  * ```
44
46
  */
45
- cssMap<TStyles extends Record<string, StrictCSSProperties & PseudosDeclarations & EnforceSchema<TSchema>>>(styles: TStyles): {
46
- readonly [P in keyof TStyles]: CompiledStyles<TStyles[P]>;
47
+ cssMap<TStylesMap extends CSSMapStyles<TSchema>>(styles: CSSMapStyles<TSchema>): {
48
+ readonly [P in keyof TStylesMap]: CompiledStyles<TStylesMap[P]>;
47
49
  };
48
50
  /**
49
51
  * ## CX
@@ -54,14 +54,14 @@ const xcss_prop_1 = require("../xcss-prop");
54
54
  function createStrictAPI() {
55
55
  return {
56
56
  css() {
57
- throw (0, error_1.createSetupError)();
57
+ throw (0, error_1.createStrictSetupError)();
58
58
  },
59
59
  cssMap() {
60
- throw (0, error_1.createSetupError)();
60
+ throw (0, error_1.createStrictSetupError)();
61
61
  },
62
62
  cx: xcss_prop_1.cx,
63
63
  XCSSProp() {
64
- throw (0, error_1.createSetupError)();
64
+ throw (0, error_1.createStrictSetupError)();
65
65
  },
66
66
  };
67
67
  }
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/create-strict-api/index.ts"],"names":[],"mappings":";;;AACA,0CAAkD;AAClD,4CAA+E;AA+J/E;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+CG;AACH,SAAgB,eAAe;IAC7B,OAAO;QACL,GAAG;YACD,MAAM,IAAA,wBAAgB,GAAE,CAAC;QAC3B,CAAC;QACD,MAAM;YACJ,MAAM,IAAA,wBAAgB,GAAE,CAAC;QAC3B,CAAC;QACD,EAAE,EAAF,cAAE;QACF,QAAQ;YACN,MAAM,IAAA,wBAAgB,GAAE,CAAC;QAC3B,CAAC;KACF,CAAC;AACJ,CAAC;AAbD,0CAaC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/create-strict-api/index.ts"],"names":[],"mappings":";;;AACA,0CAAwD;AACxD,4CAA+E;AA+J/E;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+CG;AACH,SAAgB,eAAe;IAC7B,OAAO;QACL,GAAG;YACD,MAAM,IAAA,8BAAsB,GAAE,CAAC;QACjC,CAAC;QACD,MAAM;YACJ,MAAM,IAAA,8BAAsB,GAAE,CAAC;QACjC,CAAC;QACD,EAAE,EAAF,cAAE;QACF,QAAQ;YACN,MAAM,IAAA,8BAAsB,GAAE,CAAC;QACjC,CAAC;KACF,CAAC;AACJ,CAAC;AAbD,0CAaC"}
@@ -1 +1,2 @@
1
1
  export declare const createSetupError: () => Error;
2
+ export declare const createStrictSetupError: () => Error;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.createSetupError = void 0;
3
+ exports.createStrictSetupError = exports.createSetupError = void 0;
4
4
  const createSetupError = () => {
5
5
  return new Error(`
6
6
  ██████╗ ██████╗ ███╗ ███╗██████╗ ██╗██╗ ███████╗██████╗
@@ -21,4 +21,24 @@ const createSetupError = () => {
21
21
  `);
22
22
  };
23
23
  exports.createSetupError = createSetupError;
24
+ const createStrictSetupError = () => {
25
+ return new Error(`
26
+ ██████╗ ██████╗ ███╗ ███╗██████╗ ██╗██╗ ███████╗██████╗
27
+ ██╔════╝██╔═══██╗████╗ ████║██╔══██╗██║██║ ██╔════╝██╔══██╗
28
+ ██║ ██║ ██║██╔████╔██║██████╔╝██║██║ █████╗ ██║ ██║
29
+ ██║ ██║ ██║██║╚██╔╝██║██╔═══╝ ██║██║ ██╔══╝ ██║ ██║
30
+ ╚██████╗╚██████╔╝██║ ╚═╝ ██║██║ ██║███████╗███████╗██████╔╝
31
+ ╚═════╝ ╚═════╝ ╚═╝ ╚═╝╚═╝ ╚═╝╚══════╝╚══════╝╚═════╝
32
+
33
+ @compiled/react
34
+
35
+ Code was executed when it shouldn't have. To resolve make sure to:
36
+
37
+ 1. Set up Compiled.
38
+ 2. Configure importSources in your Compiled config to point to the module that exports the output of createStrictAPI().
39
+
40
+ For more information visit https://compiledcssinjs.com/docs/installation and follow the instructions.
41
+ `);
42
+ };
43
+ exports.createStrictSetupError = createStrictSetupError;
24
44
  //# sourceMappingURL=error.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"error.js","sourceRoot":"","sources":["../../../src/utils/error.ts"],"names":[],"mappings":";;;AAAO,MAAM,gBAAgB,GAAG,GAAU,EAAE;IAC1C,OAAO,IAAI,KAAK,CAAC;;;;;;;;;;;;;;;;CAgBlB,CAAC,CAAC;AACH,CAAC,CAAC;AAlBW,QAAA,gBAAgB,oBAkB3B"}
1
+ {"version":3,"file":"error.js","sourceRoot":"","sources":["../../../src/utils/error.ts"],"names":[],"mappings":";;;AAAO,MAAM,gBAAgB,GAAG,GAAU,EAAE;IAC1C,OAAO,IAAI,KAAK,CAAC;;;;;;;;;;;;;;;;CAgBlB,CAAC,CAAC;AACH,CAAC,CAAC;AAlBW,QAAA,gBAAgB,oBAkB3B;AAEK,MAAM,sBAAsB,GAAG,GAAU,EAAE;IAChD,OAAO,IAAI,KAAK,CAAC;;;;;;;;;;;;;;;;CAgBlB,CAAC,CAAC;AACH,CAAC,CAAC;AAlBW,QAAA,sBAAsB,0BAkBjC"}
@@ -9,7 +9,9 @@ type EnforceSchema<TObject> = {
9
9
  type PickObjects<TObject> = {
10
10
  [P in keyof TObject]: TObject[P] extends Record<string, unknown> ? TObject[P] : never;
11
11
  };
12
- interface CompiledAPI<TSchema> {
12
+ type CSSStyles<TSchema extends CompiledSchema> = StrictCSSProperties & PseudosDeclarations & EnforceSchema<TSchema>;
13
+ type CSSMapStyles<TSchema extends CompiledSchema> = Record<string, CSSStyles<TSchema>>;
14
+ interface CompiledAPI<TSchema extends CompiledSchema> {
13
15
  /**
14
16
  * ## CSS
15
17
  *
@@ -25,7 +27,7 @@ interface CompiledAPI<TSchema> {
25
27
  * <div css={redText} />
26
28
  * ```
27
29
  */
28
- css(styles: StrictCSSProperties & PseudosDeclarations & EnforceSchema<TSchema>): StrictCSSProperties;
30
+ css(styles: CSSStyles<TSchema>): StrictCSSProperties;
29
31
  /**
30
32
  * ## CSS Map
31
33
  *
@@ -42,8 +44,8 @@ interface CompiledAPI<TSchema> {
42
44
  * <div css={styles.solid} />
43
45
  * ```
44
46
  */
45
- cssMap<TStyles extends Record<string, StrictCSSProperties & PseudosDeclarations & EnforceSchema<TSchema>>>(styles: TStyles): {
46
- readonly [P in keyof TStyles]: CompiledStyles<TStyles[P]>;
47
+ cssMap<TStylesMap extends CSSMapStyles<TSchema>>(styles: CSSMapStyles<TSchema>): {
48
+ readonly [P in keyof TStylesMap]: CompiledStyles<TStylesMap[P]>;
47
49
  };
48
50
  /**
49
51
  * ## CX
@@ -1,4 +1,4 @@
1
- import { createSetupError } from '../utils/error';
1
+ import { createStrictSetupError } from '../utils/error';
2
2
  import { cx } from '../xcss-prop';
3
3
  /**
4
4
  * ## Create Strict API
@@ -51,14 +51,14 @@ import { cx } from '../xcss-prop';
51
51
  export function createStrictAPI() {
52
52
  return {
53
53
  css() {
54
- throw createSetupError();
54
+ throw createStrictSetupError();
55
55
  },
56
56
  cssMap() {
57
- throw createSetupError();
57
+ throw createStrictSetupError();
58
58
  },
59
59
  cx,
60
60
  XCSSProp() {
61
- throw createSetupError();
61
+ throw createStrictSetupError();
62
62
  },
63
63
  };
64
64
  }
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/create-strict-api/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAClD,OAAO,EAAuB,EAAE,EAA0B,MAAM,cAAc,CAAC;AA+J/E;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+CG;AACH,MAAM,UAAU,eAAe;IAC7B,OAAO;QACL,GAAG;YACD,MAAM,gBAAgB,EAAE,CAAC;QAC3B,CAAC;QACD,MAAM;YACJ,MAAM,gBAAgB,EAAE,CAAC;QAC3B,CAAC;QACD,EAAE;QACF,QAAQ;YACN,MAAM,gBAAgB,EAAE,CAAC;QAC3B,CAAC;KACF,CAAC;AACJ,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/create-strict-api/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,sBAAsB,EAAE,MAAM,gBAAgB,CAAC;AACxD,OAAO,EAAuB,EAAE,EAA0B,MAAM,cAAc,CAAC;AA+J/E;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+CG;AACH,MAAM,UAAU,eAAe;IAC7B,OAAO;QACL,GAAG;YACD,MAAM,sBAAsB,EAAE,CAAC;QACjC,CAAC;QACD,MAAM;YACJ,MAAM,sBAAsB,EAAE,CAAC;QACjC,CAAC;QACD,EAAE;QACF,QAAQ;YACN,MAAM,sBAAsB,EAAE,CAAC;QACjC,CAAC;KACF,CAAC;AACJ,CAAC"}
@@ -1 +1,2 @@
1
1
  export declare const createSetupError: () => Error;
2
+ export declare const createStrictSetupError: () => Error;
@@ -17,4 +17,23 @@ export const createSetupError = () => {
17
17
  Good luck!
18
18
  `);
19
19
  };
20
+ export const createStrictSetupError = () => {
21
+ return new Error(`
22
+ ██████╗ ██████╗ ███╗ ███╗██████╗ ██╗██╗ ███████╗██████╗
23
+ ██╔════╝██╔═══██╗████╗ ████║██╔══██╗██║██║ ██╔════╝██╔══██╗
24
+ ██║ ██║ ██║██╔████╔██║██████╔╝██║██║ █████╗ ██║ ██║
25
+ ██║ ██║ ██║██║╚██╔╝██║██╔═══╝ ██║██║ ██╔══╝ ██║ ██║
26
+ ╚██████╗╚██████╔╝██║ ╚═╝ ██║██║ ██║███████╗███████╗██████╔╝
27
+ ╚═════╝ ╚═════╝ ╚═╝ ╚═╝╚═╝ ╚═╝╚══════╝╚══════╝╚═════╝
28
+
29
+ @compiled/react
30
+
31
+ Code was executed when it shouldn't have. To resolve make sure to:
32
+
33
+ 1. Set up Compiled.
34
+ 2. Configure importSources in your Compiled config to point to the module that exports the output of createStrictAPI().
35
+
36
+ For more information visit https://compiledcssinjs.com/docs/installation and follow the instructions.
37
+ `);
38
+ };
20
39
  //# sourceMappingURL=error.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"error.js","sourceRoot":"","sources":["../../../src/utils/error.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,gBAAgB,GAAG,GAAU,EAAE;IAC1C,OAAO,IAAI,KAAK,CAAC;;;;;;;;;;;;;;;;CAgBlB,CAAC,CAAC;AACH,CAAC,CAAC"}
1
+ {"version":3,"file":"error.js","sourceRoot":"","sources":["../../../src/utils/error.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,gBAAgB,GAAG,GAAU,EAAE;IAC1C,OAAO,IAAI,KAAK,CAAC;;;;;;;;;;;;;;;;CAgBlB,CAAC,CAAC;AACH,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,sBAAsB,GAAG,GAAU,EAAE;IAChD,OAAO,IAAI,KAAK,CAAC;;;;;;;;;;;;;;;;CAgBlB,CAAC,CAAC;AACH,CAAC,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@compiled/react",
3
- "version": "0.16.3",
3
+ "version": "0.16.5",
4
4
  "description": "A familiar and performant compile time CSS-in-JS library for React.",
5
5
  "keywords": [
6
6
  "compiled",
@@ -1,4 +1,4 @@
1
- import { createStrictAPI } from '@compiled/react';
1
+ import { createStrictAPI } from '../../index';
2
2
 
3
3
  const { css, XCSSProp, cssMap, cx } = createStrictAPI<{
4
4
  '&:hover': {
@@ -86,6 +86,56 @@ describe('createStrictAPI()', () => {
86
86
 
87
87
  expect(getByTestId('div')).toHaveCompiledCss('all', 'inherit');
88
88
  });
89
+
90
+ it('should type error with css properties not in the style scope', () => {
91
+ // NOTE: These are split into mutliple `css()` calls to ensure the type errors are not hidden
92
+ // as only one will error at a time when combined into one query
93
+
94
+ const bgStyles = css({
95
+ fontWeight: 'bold', // just a valid property to ensure the `extends` keyword isn't working as intended
96
+ // @ts-expect-error - Object literal may only specify known properties, and 'bg' does not exist in type …
97
+ bg: 'red',
98
+ });
99
+
100
+ const colourStyles = css({
101
+ fontWeight: 'bold', // just a valid property to ensure the `extends` keyword isn't working as intended
102
+ // @ts-expect-error - Object literal may only specify known properties, and 'colour' does not exist in type …
103
+ colour: 'var(--ds-text)',
104
+ });
105
+
106
+ const hoverStyles = css({
107
+ fontWeight: 'bold', // just a valid property to ensure the `extends` keyword isn't working as intended
108
+ '&:hover': {
109
+ fontWeight: 'bold', // just a valid property to ensure the `extends` keyword isn't working as intended
110
+ // @ts-expect-error - Object literal may only specify known properties, and 'colour' does not exist in type …
111
+ colour: 'var(--ds-text-hover)',
112
+ },
113
+ });
114
+
115
+ const invalidPsuedoStyles = css({
116
+ fontWeight: 'bold', // just a valid property to ensure the `extends` keyword isn't working as intended
117
+ // @ts-expect-error - bject literal may only specify known properties, and ''&:invalid-pseudo'' does not exist in type …
118
+ '&:invalid-pseudo': {
119
+ color: 'var(--ds-text)',
120
+ },
121
+ });
122
+
123
+ const { getByTestId } = render(
124
+ <div css={[bgStyles, colourStyles, hoverStyles, invalidPsuedoStyles]} data-testid="div" />
125
+ );
126
+
127
+ expect(getByTestId('div')).toHaveCompiledCss('font-weight', 'bold');
128
+ expect(getByTestId('div')).toHaveCompiledCss('font-weight', 'bold', {
129
+ target: ':hover',
130
+ });
131
+
132
+ // These still get compiled to css, even if they're not valid
133
+ expect(getByTestId('div')).toHaveCompiledCss('bg', 'red');
134
+ expect(getByTestId('div')).toHaveCompiledCss('colour', 'var(--ds-text)');
135
+ expect(getByTestId('div')).toHaveCompiledCss('colour', 'var(--ds-text-hover)', {
136
+ target: ':hover',
137
+ });
138
+ });
89
139
  });
90
140
 
91
141
  describe('cssMap()', () => {
@@ -152,6 +202,72 @@ describe('createStrictAPI()', () => {
152
202
 
153
203
  expect(getByTestId('div')).toHaveCompiledCss('val', 'ok', { target: ':hover' });
154
204
  });
205
+
206
+ it('should type error with css properties not in the style scope', () => {
207
+ // NOTE: These are split into mutliple `css()` calls to ensure the type errors are not hidden
208
+ // as only one will error at a time when combined into one query
209
+
210
+ const bgStyles = cssMap({
211
+ primary: {
212
+ fontWeight: 'bold', // just a valid property to ensure the `extends` keyword isn't working as intended
213
+ // @ts-expect-error - Object literal may only specify known properties, and 'bg' does not exist in type …
214
+ bg: 'red',
215
+ },
216
+ });
217
+
218
+ const colourStyles = cssMap({
219
+ primary: {
220
+ fontWeight: 'bold', // just a valid property to ensure the `extends` keyword isn't working as intended
221
+ // @ts-expect-error - Object literal may only specify known properties, and 'colour' does not exist in type …
222
+ colour: 'var(--ds-text)',
223
+ },
224
+ });
225
+
226
+ const hoverStyles = cssMap({
227
+ primary: {
228
+ fontWeight: 'bold', // just a valid property to ensure the `extends` keyword isn't working as intended
229
+ '&:hover': {
230
+ fontWeight: 'bold', // just a valid property to ensure the `extends` keyword isn't working as intended
231
+ // @ts-expect-error - Object literal may only specify known properties, and 'colour' does not exist in type …
232
+ colour: 'var(--ds-text-hover)',
233
+ },
234
+ },
235
+ });
236
+
237
+ const invalidPsuedoStyles = cssMap({
238
+ primary: {
239
+ fontWeight: 'bold', // just a valid property to ensure the `extends` keyword isn't working as intended
240
+ // @ts-expect-error - bject literal may only specify known properties, and ''&:invalid-pseudo'' does not exist in type …
241
+ '&:invalid-pseudo': {
242
+ color: 'var(--ds-text)',
243
+ },
244
+ },
245
+ });
246
+
247
+ const { getByTestId } = render(
248
+ <div
249
+ css={[
250
+ bgStyles.primary,
251
+ colourStyles.primary,
252
+ hoverStyles.primary,
253
+ invalidPsuedoStyles.primary,
254
+ ]}
255
+ data-testid="div"
256
+ />
257
+ );
258
+
259
+ expect(getByTestId('div')).toHaveCompiledCss('font-weight', 'bold');
260
+ expect(getByTestId('div')).toHaveCompiledCss('font-weight', 'bold', {
261
+ target: ':hover',
262
+ });
263
+
264
+ // These still get compiled to css, even if they're not valid
265
+ expect(getByTestId('div')).toHaveCompiledCss('bg', 'red');
266
+ expect(getByTestId('div')).toHaveCompiledCss('colour', 'var(--ds-text)');
267
+ expect(getByTestId('div')).toHaveCompiledCss('colour', 'var(--ds-text-hover)', {
268
+ target: ':hover',
269
+ });
270
+ });
155
271
  });
156
272
 
157
273
  describe('XCSSProp', () => {
@@ -1,5 +1,5 @@
1
1
  import type { StrictCSSProperties, CSSPseudos } from '../types';
2
- import { createSetupError } from '../utils/error';
2
+ import { createStrictSetupError } from '../utils/error';
3
3
  import { type CompiledStyles, cx, type Internal$XCSSProp } from '../xcss-prop';
4
4
 
5
5
  type PseudosDeclarations = {
@@ -18,7 +18,12 @@ type PickObjects<TObject> = {
18
18
  [P in keyof TObject]: TObject[P] extends Record<string, unknown> ? TObject[P] : never;
19
19
  };
20
20
 
21
- interface CompiledAPI<TSchema> {
21
+ type CSSStyles<TSchema extends CompiledSchema> = StrictCSSProperties &
22
+ PseudosDeclarations &
23
+ EnforceSchema<TSchema>;
24
+ type CSSMapStyles<TSchema extends CompiledSchema> = Record<string, CSSStyles<TSchema>>;
25
+
26
+ interface CompiledAPI<TSchema extends CompiledSchema> {
22
27
  /**
23
28
  * ## CSS
24
29
  *
@@ -34,9 +39,7 @@ interface CompiledAPI<TSchema> {
34
39
  * <div css={redText} />
35
40
  * ```
36
41
  */
37
- css(
38
- styles: StrictCSSProperties & PseudosDeclarations & EnforceSchema<TSchema>
39
- ): StrictCSSProperties;
42
+ css(styles: CSSStyles<TSchema>): StrictCSSProperties;
40
43
  /**
41
44
  * ## CSS Map
42
45
  *
@@ -53,15 +56,12 @@ interface CompiledAPI<TSchema> {
53
56
  * <div css={styles.solid} />
54
57
  * ```
55
58
  */
56
- cssMap<
57
- TStyles extends Record<
58
- string,
59
- StrictCSSProperties & PseudosDeclarations & EnforceSchema<TSchema>
60
- >
61
- >(
62
- styles: TStyles
59
+ cssMap<TStylesMap extends CSSMapStyles<TSchema>>(
60
+ // NOTE: This should match the generic `TStylesMap extends …` as we want this arg to strictly satisfy this type, not just extend it.
61
+ // The "extends" functionality is to infer and build the return type, this is to enforce the input type.
62
+ styles: CSSMapStyles<TSchema>
63
63
  ): {
64
- readonly [P in keyof TStyles]: CompiledStyles<TStyles[P]>;
64
+ readonly [P in keyof TStylesMap]: CompiledStyles<TStylesMap[P]>;
65
65
  };
66
66
  /**
67
67
  * ## CX
@@ -210,14 +210,14 @@ type CompiledSchema = StrictCSSProperties & PseudosDeclarations;
210
210
  export function createStrictAPI<TSchema extends CompiledSchema>(): CompiledAPI<TSchema> {
211
211
  return {
212
212
  css() {
213
- throw createSetupError();
213
+ throw createStrictSetupError();
214
214
  },
215
215
  cssMap() {
216
- throw createSetupError();
216
+ throw createStrictSetupError();
217
217
  },
218
218
  cx,
219
219
  XCSSProp() {
220
- throw createSetupError();
220
+ throw createStrictSetupError();
221
221
  },
222
222
  };
223
223
  }
@@ -17,3 +17,23 @@ export const createSetupError = (): Error => {
17
17
  Good luck!
18
18
  `);
19
19
  };
20
+
21
+ export const createStrictSetupError = (): Error => {
22
+ return new Error(`
23
+ ██████╗ ██████╗ ███╗ ███╗██████╗ ██╗██╗ ███████╗██████╗
24
+ ██╔════╝██╔═══██╗████╗ ████║██╔══██╗██║██║ ██╔════╝██╔══██╗
25
+ ██║ ██║ ██║██╔████╔██║██████╔╝██║██║ █████╗ ██║ ██║
26
+ ██║ ██║ ██║██║╚██╔╝██║██╔═══╝ ██║██║ ██╔══╝ ██║ ██║
27
+ ╚██████╗╚██████╔╝██║ ╚═╝ ██║██║ ██║███████╗███████╗██████╔╝
28
+ ╚═════╝ ╚═════╝ ╚═╝ ╚═╝╚═╝ ╚═╝╚══════╝╚══════╝╚═════╝
29
+
30
+ @compiled/react
31
+
32
+ Code was executed when it shouldn't have. To resolve make sure to:
33
+
34
+ 1. Set up Compiled.
35
+ 2. Configure importSources in your Compiled config to point to the module that exports the output of createStrictAPI().
36
+
37
+ For more information visit https://compiledcssinjs.com/docs/installation and follow the instructions.
38
+ `);
39
+ };