Skip to content

Commit 4513356

Browse files
authored
Merge pull request #665 from hasparus/typescript-spike
Add resolveJsonModule to @theme-ui/core tsconfig
2 parents 66ff3c3 + f340c9c commit 4513356

File tree

5 files changed

+24
-12
lines changed

5 files changed

+24
-12
lines changed

packages/core/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
"react": "^16.11.0"
2626
},
2727
"devDependencies": {
28+
"@types/react": "^16.9.19",
2829
"react": "^16.11.0"
2930
}
3031
}

packages/core/src/index.ts

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import {
66
import { css } from '@theme-ui/css'
77
import React from 'react'
88
import deepmerge from 'deepmerge'
9-
// @ts-ignore
109
import { version as __EMOTION_VERSION__ } from '@emotion/core/package.json'
1110
import { Theme } from './theme'
1211

@@ -34,10 +33,11 @@ const parseProps = props => {
3433
export const jsx: typeof React.createElement = (type, props, ...children) =>
3534
emotion.apply(undefined, [type, parseProps(props), ...children])
3635

37-
export const Context = React.createContext<{
36+
export interface ContextValue {
3837
__EMOTION_VERSION__: string
3938
theme: Theme | null
40-
}>({
39+
}
40+
export const Context = React.createContext<ContextValue>({
4141
__EMOTION_VERSION__,
4242
theme: null,
4343
})
@@ -60,12 +60,16 @@ const isMergeableObject = n => {
6060

6161
const arrayMerge = (destinationArray, sourceArray, options) => sourceArray
6262

63-
export const merge = (a, b) =>
63+
export const merge = <T>(a: Partial<T>, b: Partial<T>): T =>
6464
deepmerge(a, b, { isMergeableObject, arrayMerge })
6565

66-
merge.all = (...args) => deepmerge.all(args, { isMergeableObject, arrayMerge })
66+
merge.all = <T>(...args: Partial<T>[]) =>
67+
deepmerge.all<T>(args, { isMergeableObject, arrayMerge })
6768

68-
const BaseProvider = ({ context, children }) =>
69+
interface BaseProviderProps {
70+
context: ContextValue
71+
}
72+
const BaseProvider: React.FC<BaseProviderProps> = ({ context, children }) =>
6973
jsx(
7074
EmotionContext.Provider,
7175
{ value: context.theme },
@@ -96,10 +100,7 @@ export function ThemeProvider({ theme, children }: ThemeProviderProps) {
96100
const context =
97101
typeof theme === 'function'
98102
? { ...outer, theme: theme(outer.theme) }
99-
: merge.all({}, outer, { theme })
103+
: merge.all<ContextValue>({}, outer, { theme })
100104

101-
return jsx(BaseProvider, {
102-
context,
103-
children,
104-
})
105+
return jsx(BaseProvider, { context }, children)
105106
}
File renamed without changes.

packages/core/tsconfig.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
{
22
"compilerOptions": {
3-
"esModuleInterop": true
3+
"resolveJsonModule": true,
4+
"esModuleInterop": true,
5+
"moduleResolution": "node"
46
}
57
}

yarn.lock

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3549,6 +3549,14 @@
35493549
"@types/prop-types" "*"
35503550
csstype "^2.2.0"
35513551

3552+
"@types/react@^16.9.19":
3553+
version "16.9.19"
3554+
resolved "https://registry.yarnpkg.com/@types/react/-/react-16.9.19.tgz#c842aa83ea490007d29938146ff2e4d9e4360c40"
3555+
integrity sha512-LJV97//H+zqKWMms0kvxaKYJDG05U2TtQB3chRLF8MPNs+MQh/H1aGlyDUxjaHvu08EAGerdX2z4LTBc7ns77A==
3556+
dependencies:
3557+
"@types/prop-types" "*"
3558+
csstype "^2.2.0"
3559+
35523560
35533561
version "0.0.8"
35543562
resolved "https://registry.yarnpkg.com/@types/resolve/-/resolve-0.0.8.tgz#f26074d238e02659e323ce1a13d041eee280e194"

0 commit comments

Comments
 (0)