Skip to content

Commit 401b794

Browse files
committed
fix(types): don't lock csstype version
1 parent 28d1a87 commit 401b794

File tree

6 files changed

+15
-123
lines changed

6 files changed

+15
-123
lines changed

packages/css/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
"access": "public"
3636
},
3737
"dependencies": {
38-
"csstype": "3.0.10"
38+
"csstype": "^3.0.10"
3939
},
4040
"peerDependencies": {
4141
"@emotion/react": "^11.11.1"

packages/css/test/errors-and-inference.ts

-63
Original file line numberDiff line numberDiff line change
@@ -7,42 +7,6 @@ const expectSnippet = expecter(`
77
`)
88

99
describe('Theme', () => {
10-
test('shows friendly error only on bad property', () => {
11-
expectSnippet(`
12-
css({
13-
bg: 'salmon',
14-
whiteSpace: 'no-works',
15-
'> form': {
16-
color: 'blue',
17-
widows: 'bar',
18-
// unknown CSS property is accepted
19-
whitePace: 'this-works',
20-
},
21-
})
22-
`).toFail(
23-
/Error snippet\.tsx \(\d+,\d+\): Type '"no-works"' is not assignable to type [\s\S]+'./
24-
)
25-
})
26-
27-
test('shows friendly error on nested object', () => {
28-
expectSnippet(`
29-
css({
30-
bg: 'salmon',
31-
'> form': {
32-
color: 'blue',
33-
whiteSpace: 'banana',
34-
},
35-
})
36-
`).toFail(
37-
new RegExp(
38-
`Error snippet\\.tsx \\(\\d+,\\d+\\): Type '{ color: "blue"; whiteSpace: "banana"; }'` +
39-
` is not assignable to type '[\\s\\S]+'.\\n\\s+` +
40-
`Types of property 'whiteSpace' are incompatible.\\n\\s+` +
41-
`Type '"banana"' is not assignable to type [\\s\\S]+`
42-
)
43-
)
44-
})
45-
4610
test('accepts unknown CSS property without error', () => {
4711
expect(css({ '> form': { windows: 'baz' } })({})).toStrictEqual({
4812
'> form': { windows: 'baz' },
@@ -96,9 +60,6 @@ describe('Theme', () => {
9660
css({ size: (t) => get(t, 'space.3') + get(t, 'sizes.5') })
9761

9862
const parse = (x: string | number | undefined | {}) => parseInt(String(x))
99-
css({
100-
size: (t) => parse(t.space?.[3]) + parse(t.sizes?.[5]),
101-
})
10263

10364
// Current limitation. If you broke this one, that's actually pretty awesome,
10465
// but TypeScript chapter in the docs needs an update.
@@ -110,30 +71,6 @@ describe('Theme', () => {
11071
})
11172
})
11273

113-
// This is not a feature, but the TypeScript chapter in the docs will need an
114-
// update if this test fails.
115-
test('inferred type `string` is too wide for `whiteSpace`', () => {
116-
expectSnippet(`
117-
const style = {
118-
whiteSpace: 'pre-line'
119-
}
120-
121-
css(style);
122-
`).toFail(
123-
/Type '{ whiteSpace: string; }' is not assignable to type 'ThemeUICSSObject'./
124-
)
125-
126-
expectSnippet(`
127-
import { ThemeUICSSObject } from './packages/css'
128-
129-
const style: ThemeUICSSObject = {
130-
whiteSpace: 'pre-line'
131-
}
132-
133-
css(style);
134-
`).toSucceed()
135-
})
136-
13774
describe('ColorMode', () => {
13875
const expectedSnippet = expectSnippet(`
13976
import { ColorMode } from './packages/css/src'

packages/css/test/past-bugs.ts

+7
Original file line numberDiff line numberDiff line change
@@ -32,3 +32,10 @@ describe('theme scales, get and default object property (#1439)', () => {
3232
expect(actual).toStrictEqual({ zIndex: 1 })
3333
})
3434
})
35+
36+
// https://github.com/system-ui/theme-ui/issues/2520
37+
it('accepts number as aspect ratio', () => {
38+
const actual = css({ aspectRatio: 0.5 })({})
39+
40+
expect(actual).toStrictEqual({ aspectRatio: 0.5 })
41+
})

packages/docs/src/pages/guides/typescript.mdx

-47
Original file line numberDiff line numberDiff line change
@@ -127,50 +127,3 @@ const syntaxHighlighting = theme.syntaxHighlighting
127127

128128
_[Try it in TypeScript Playground.](https://www.typescriptlang.org/v2/en/play?#code/JYWwDg9gTgLgBAbzgFQBYFMTrgXzgMyghDgHIYMsBaAV2FIG4AoJ4AOxnSnwEMBjbAFkAngGVhHHgA8AEsADmqADYLUMdvLSZsCJnALR08ojTYATAFxwAzjCgbmOFmfR8lPKNhAQzNJdnJKdFp6RD04dk5ufmwtLDD9fWsJGGk5RRVFdTZ5KxFxSVlVTLUNOPRwpycmPgg2WzgKbStyuABeBJsUtOLVbNzO-XxDYwhTSzIAYgAmWdIAGkqmHGYauobkwvTlPo12xqCAOk3UoozdnLX6+C4iKH2mrGPhGDYe86yNJiA)_
129129

130-
## Common Problems
131-
132-
### Union types are not inferred without explicit annotation
133-
134-
Style objects defined outside of `css` function and `sx` prop need explicit
135-
annotation to prevent following error.
136-
137-
```tsx
138-
/** @jsxImportSource theme-ui */
139-
140-
const style = { whiteSpace: 'pre-line' }
141-
142-
// Type '{ whiteSpace: string; }' is not assignable to type 'ThemeUICSSObject'.
143-
// Type 'string' is not assignable to type '"inherit" | "initial" | "revert" | "unset" | "normal" | "break-spaces"
144-
return <div sx={style} />
145-
```
146-
147-
_[Try it on CodeSandbox.](https://codesandbox.io/s/theme-ui-inferrence-too-wide-vkrf5?file=/src/index.tsx&view=editor&previewwindow=tests)_
148-
149-
TypeScript assumes that `whiteSpace` here is a `string`, but the `whiteSpace`
150-
property in `ThemeUICSSObject` is a union of possible white-space values
151-
([see on MDN](https://developer.mozilla.org/en-US/docs/Web/CSS/white-space#Values))
152-
or a nested style object.
153-
154-
We can explicitly annotate `style` ensure that it is a correct Theme UI style
155-
object and that `whiteSpace` is one of appropriate values.
156-
157-
```tsx
158-
/** @jsxImportSource theme-ui */
159-
import { ThemeUICSSObject } from 'theme-ui'
160-
161-
const style: ThemeUICSSObject = { whiteSpace: 'pre-line' }
162-
163-
// No error
164-
return <div sx={style} />
165-
```
166-
167-
_[Try it on CodeSandbox.](https://codesandbox.io/s/theme-ui-inferrence-too-wide-vkrf5?file=/src/index.tsx&view=editor&previewwindow=tests)_
168-
169-
We could also fix our problem by narrowing the type of `style` with a
170-
[const assertion](https://www.typescriptlang.org/docs/handbook/release-notes/typescript-3-4.html#const-assertions).
171-
172-
```tsx
173-
const style = { whiteSpace: 'pre-line' } as const
174-
```
175-
176-
This is succinct, but error prone, because we won't get TS intellisense support inside of this object.

packages/typography/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
"@types/modularscale": "^2.0.0",
1414
"@types/typography": "^0.16.4",
1515
"compass-vertical-rhythm": "^1.4.5",
16-
"csstype": "3.0.10",
16+
"csstype": "^3.0.10",
1717
"modularscale": "^2.0.1",
1818
"type-fest": "^2.18.0"
1919
},

pnpm-lock.yaml

+6-11
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)