Skip to content
This repository was archived by the owner on Jun 20, 2022. It is now read-only.

Commit 87eda0b

Browse files
elliottsjgregberge
authored andcommitted
fix(types): fix TypeScript definitions (#108)
- Adjust the build step so core-em and core-sc have their own independent type definitions, and copy the shared definitions to a 'shared/index.d.ts' module. - Add a "tsc:check" CI script to ensure type definition correctness.
1 parent c5f3c75 commit 87eda0b

File tree

6 files changed

+109
-35
lines changed

6 files changed

+109
-35
lines changed

config/rollup.js

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,20 @@ export const getRollupConfig = ({
2424
exclude: 'node_modules/**',
2525
configFile: path.join(pwd, '../../babel.config.js'),
2626
}),
27-
copyTypeScriptDefs
28-
? copy({
29-
files: `${CORE_DIR}/*.d.ts`,
30-
dest: DIST_DIR,
31-
})
32-
: null,
27+
...(
28+
copyTypeScriptDefs
29+
? [
30+
copy({
31+
files: `${CORE_DIR}/*.d.ts`,
32+
dest: `${DIST_DIR}/shared`,
33+
}),
34+
copy({
35+
files: `${SOURCE_DIR}/*.d.ts`,
36+
dest: DIST_DIR
37+
})
38+
]
39+
: []
40+
),
3341
],
3442
}
3543

package.json

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,13 @@
77
"build": "lerna run build",
88
"build:docs": "yarn build && docz build && cp _redirects .docz/dist",
99
"build:watch": "WATCH_MODE=true lerna run --parallel build -- --watch",
10-
"ci": "yarn lint && yarn test && yarn build && bundlesize",
10+
"ci": "yarn lint && yarn test && yarn build && yarn tsc:check && bundlesize",
1111
"dev": "docz dev",
1212
"format": "prettier --write \"**/*.{js,json,md,mdx}\"",
1313
"lint": "eslint .",
1414
"release": "lerna publish --conventional-commits --force-publish=* && conventional-github-releaser --preset angular",
15-
"test": "jest"
15+
"test": "jest",
16+
"tsc:check": "tsc --noEmit --strict ./packages/core-em/dist/index.d.ts ./packages/core-sc/dist/index.d.ts"
1617
},
1718
"bundlesize": [
1819
{
@@ -36,6 +37,8 @@
3637
"@emotion/core": "^10.0.7",
3738
"@emotion/styled": "^10.0.7",
3839
"@material-ui/system": "^3.0.0-alpha.2",
40+
"@types/react": "^16.7.22",
41+
"@types/styled-components": "^4.1.6",
3942
"babel-core": "^7.0.0-0",
4043
"babel-eslint": "^10.0.1",
4144
"babel-jest": "^24.0.0",
@@ -79,6 +82,7 @@
7982
"standard-version": "^4.4.0",
8083
"styled-components": "^4.1.3",
8184
"styled-system": "^3.2.1",
85+
"typescript": "^3.3.1",
8286
"terser": "3.14.1",
8387
"uglifyjs-webpack-plugin": "^2.1.1",
8488
"webpack": "^4.29.0"

packages/core-em/src/index.d.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import * as emotionCore from '@emotion/core'
2+
import { withTheme } from 'emotion-theming'
3+
import { ThemeType } from './shared'
4+
5+
export * from './shared'
6+
7+
export const Normalize: ReturnType<typeof withTheme>
8+
9+
export type ResponsiveUtilityStyles =
10+
| string
11+
| emotionCore.ArrayInterpolation<undefined>
12+
13+
export const up: (
14+
name: string | number,
15+
code: ResponsiveUtilityStyles,
16+
) => (props: Object) => any
17+
18+
export const down: (
19+
name: string | number,
20+
code: ResponsiveUtilityStyles,
21+
) => (props: Object) => any
22+
23+
export const between: (
24+
lower: string | number,
25+
upper: string | number,
26+
code: ResponsiveUtilityStyles,
27+
) => (props: Object) => any

packages/core-sc/src/index.d.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import * as styledComponents from 'styled-components'
2+
import { ThemeType } from './shared'
3+
4+
export * from './shared'
5+
6+
export const Normalize: styledComponents.GlobalStyleComponent<{__scTheme?: ThemeType},ThemeType>
7+
8+
export type ResponsiveUtilityStyles =
9+
| string
10+
| styledComponents.FlattenSimpleInterpolation
11+
12+
export const up: (
13+
name: string | number,
14+
code: ResponsiveUtilityStyles,
15+
) => (props: Object) => any
16+
17+
export const down: (
18+
name: string | number,
19+
code: ResponsiveUtilityStyles,
20+
) => (props: Object) => any
21+
22+
export const between: (
23+
lower: string | number,
24+
upper: string | number,
25+
code: ResponsiveUtilityStyles,
26+
) => (props: Object) => any

packages/shared/core/index.d.ts

Lines changed: 4 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
/// <reference types="react" />
22

33
import * as React from 'react'
4-
import * as styledComponents from 'styled-components'
54

65
export type DefaultColors = 'primary'
76
| 'secondary'
@@ -16,9 +15,9 @@ export type Sizes = "sm" | "md" | "lg"
1615

1716
interface InputType {
1817
checked?: boolean
19-
onChange?: (e) => void
20-
onFocus?: (e) => void
21-
onBlur?: (e) => void
18+
onChange?: React.ChangeEventHandler<HTMLInputElement>
19+
onFocus?: React.FocusEventHandler<HTMLInputElement>
20+
onBlur?: React.FocusEventHandler<HTMLInputElement>
2221
style?: React.CSSProperties
2322
}
2423

@@ -595,7 +594,7 @@ export const lazyTh: (name: string) => (props: Object) => string
595594

596595
export const th: (
597596
name: string,
598-
transform?: (res) => string,
597+
transform?: (res: any) => string,
599598
) => (props: Object) => string
600599

601600
export const mixin: (
@@ -630,8 +629,6 @@ export const composeStyles: (
630629
...funcs: Array<(props: Object) => string>
631630
) => ((props: Object) => Object)
632631

633-
export const Normalize: styledComponents.GlobalStyleComponent<{__scTheme?: ThemeType},ThemeType>
634-
635632
export interface ModalProps extends BoxProps {
636633
children?: React.ReactNode
637634
onClose?: () => void
@@ -721,23 +718,3 @@ export const mediaBetweenWidth: (
721718
min: string | number,
722719
max: string | number,
723720
) => string
724-
725-
export type ResponsiveUtilityStyles =
726-
| string
727-
| styledComponents.FlattenSimpleInterpolation
728-
729-
export const up: (
730-
name: string | number,
731-
code: ResponsiveUtilityStyles,
732-
) => (props: Object) => any
733-
734-
export const down: (
735-
name: string | number,
736-
code: ResponsiveUtilityStyles,
737-
) => (props: Object) => any
738-
739-
export const between: (
740-
lower: string | number,
741-
upper: string | number,
742-
code: ResponsiveUtilityStyles,
743-
) => (props: Object) => any

yarn.lock

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1792,6 +1792,28 @@
17921792
resolved "https://registry.yarnpkg.com/@types/q/-/q-1.5.1.tgz#48fd98c1561fe718b61733daed46ff115b496e18"
17931793
integrity sha512-eqz8c/0kwNi/OEHQfvIuJVLTst3in0e7uTKeuY+WL/zfKn0xVujOTp42bS/vUUokhK5P2BppLd9JXMOMHcgbjA==
17941794

1795+
"@types/prop-types@*":
1796+
version "15.5.8"
1797+
resolved "https://registry.yarnpkg.com/@types/prop-types/-/prop-types-15.5.8.tgz#8ae4e0ea205fe95c3901a5a1df7f66495e3a56ce"
1798+
integrity sha512-3AQoUxQcQtLHsK25wtTWIoIpgYjH3vSDroZOUr7PpCHw/jLY1RB9z9E8dBT/OSmwStVgkRNvdh+ZHNiomRieaw==
1799+
1800+
"@types/react@*", "@types/react@^16.7.22":
1801+
version "16.7.22"
1802+
resolved "https://registry.yarnpkg.com/@types/react/-/react-16.7.22.tgz#5bc6d166d5ac34b835756f0b736c7b1af0043e81"
1803+
integrity sha512-j/3tVoY09kHcTfbia4l67ofQn9xvktUvlC/4QN0KuBHAXlbU/wuGKMb8WfEb/vIcWxsOxHv559uYprkFDFfP8Q==
1804+
dependencies:
1805+
"@types/prop-types" "*"
1806+
csstype "^2.2.0"
1807+
1808+
"@types/styled-components@^4.1.6":
1809+
version "4.1.6"
1810+
resolved "https://registry.yarnpkg.com/@types/styled-components/-/styled-components-4.1.6.tgz#9aa1d47dbc6bae540083869bcc6c639c6e9af0fe"
1811+
integrity sha512-w/ra/Tk9oPMvWpWId7esZNY1MOa6E9BYUPLl4scVJdYnrYuy5ITLbku8dGDCVH/vjjuegrHBCRYvFLQOYJ+uHg==
1812+
dependencies:
1813+
"@types/node" "*"
1814+
"@types/react" "*"
1815+
csstype "^2.2.0"
1816+
17951817
"@types/unist@*", "@types/unist@^2.0.0":
17961818
version "2.0.2"
17971819
resolved "https://registry.yarnpkg.com/@types/unist/-/unist-2.0.2.tgz#5dc0a7f76809b7518c0df58689cd16a19bd751c6"
@@ -4359,6 +4381,11 @@ cssstyle@^1.0.0:
43594381
dependencies:
43604382
cssom "0.3.x"
43614383

4384+
csstype@^2.2.0:
4385+
version "2.6.2"
4386+
resolved "https://registry.yarnpkg.com/csstype/-/csstype-2.6.2.tgz#3043d5e065454579afc7478a18de41909c8a2f01"
4387+
integrity sha512-Rl7PvTae0pflc1YtxtKbiSqq20Ts6vpIYOD5WBafl4y123DyHUeLrRdQP66sQW8/6gmX8jrYJLXwNeMqYVJcow==
4388+
43624389
csstype@^2.5.7:
43634390
version "2.6.2"
43644391
resolved "https://registry.yarnpkg.com/csstype/-/csstype-2.6.2.tgz#3043d5e065454579afc7478a18de41909c8a2f01"
@@ -13374,6 +13401,11 @@ typedarray@^0.0.6:
1337413401
resolved "https://registry.yarnpkg.com/typedarray/-/typedarray-0.0.6.tgz#867ac74e3864187b1d3d47d996a78ec5c8830777"
1337513402
integrity sha1-hnrHTjhkGHsdPUfZlqeOxciDB3c=
1337613403

13404+
typescript@^3.3.1:
13405+
version "3.3.1"
13406+
resolved "https://registry.yarnpkg.com/typescript/-/typescript-3.3.1.tgz#6de14e1db4b8a006ac535e482c8ba018c55f750b"
13407+
integrity sha512-cTmIDFW7O0IHbn1DPYjkiebHxwtCMU+eTy30ZtJNBPF9j2O1ITu5XH2YnBeVRKWHqF+3JQwWJv0Q0aUgX8W7IA==
13408+
1337713409
ua-parser-js@^0.7.18:
1337813410
version "0.7.19"
1337913411
resolved "https://registry.yarnpkg.com/ua-parser-js/-/ua-parser-js-0.7.19.tgz#94151be4c0a7fb1d001af7022fdaca4642659e4b"

0 commit comments

Comments
 (0)