Skip to content

Commit 3fc8610

Browse files
Port over minimal TS configs, deps and port Pane (#1590)
1 parent ace0f1f commit 3fc8610

File tree

24 files changed

+848
-231
lines changed

24 files changed

+848
-231
lines changed

.babelrc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"presets": ["@babel/preset-env", "@babel/preset-react"],
2+
"presets": ["@babel/preset-env", "@babel/preset-react", "@babel/preset-typescript"],
33
"plugins": [
44
"@babel/plugin-transform-runtime",
55
"@babel/plugin-proposal-class-properties",

.eslintignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@ docs/**/*.tsx
22
docs/**/*.ts
33
docs/**/*.js
44
tools/**/*
5-
codemods/**/*
5+
codemods/**/*

.eslintrc.json

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,17 @@
11
{
2-
"parser": "babel-eslint",
2+
"parser": "@typescript-eslint/parser",
33
"env": {
4-
"browser": true
4+
"browser": true,
5+
"jest": true
56
},
6-
"extends": ["plugin:react/recommended", "plugin:react-hooks/recommended", "standard", "prettier", "prettier/react"],
7+
"extends": [
8+
"plugin:react/recommended",
9+
"plugin:react-hooks/recommended",
10+
"standard",
11+
"prettier",
12+
"prettier/react",
13+
"plugin:@typescript-eslint/eslint-recommended"
14+
],
715
"settings": {
816
"react": {
917
"version": "detect"
@@ -14,12 +22,14 @@
1422
"jsx": true
1523
},
1624
"ecmaVersion": 2015,
25+
"project": "tsconfig.json",
1726
"sourceType": "module"
1827
},
19-
"plugins": ["react", "react-hooks", "sort-destructure-keys"],
28+
"plugins": ["@typescript-eslint", "react", "react-hooks", "sort-destructure-keys"],
2029
"rules": {
2130
"space-before-function-paren": "off",
22-
"no-unused-vars": "error",
31+
"no-unused-vars": "off",
32+
"@typescript-eslint/no-unused-vars": "warn",
2333
"react/display-name": "off",
2434
"sort-destructure-keys/sort-destructure-keys": "error",
2535
"no-console": [
@@ -45,11 +55,15 @@
4555
"caseInsensitive": true
4656
}
4757
}
48-
]
58+
],
59+
"react/prop-types": "off",
60+
"no-use-before-define": "off",
61+
"@typescript-eslint/no-use-before-define": ["off"],
62+
"@typescript-eslint/consistent-type-exports": "error"
4963
},
5064
"overrides": [
5165
{
52-
"files": ["*.test.js"],
66+
"files": ["*.test.js", "*.test.ts", "*.test.tsx"],
5367
"env": {
5468
"jest": true
5569
}

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ jobs:
4444
run: yarn run build
4545

4646
- name: Run prettier
47-
run: yarn run prettier 'src/**/*.{js,jsx,ts,jsx}' --check
47+
run: yarn run prettier 'src/**/*.{js,ts,tsx}' --check
4848

4949
- name: Run test
5050
run: yarn run test

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,4 @@ coverage
1313
/storybook-static/
1414
.eslintcache
1515
/codemods/dist
16+
/types/

index.d.ts

Lines changed: 26 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,34 @@
1-
/* tslint:disable:interface-name max-classes-per-file no-empty-interface */
1+
// @ts-nocheck Disabling TS checking on this file while definitions are being ported over to src files
22

33
import * as React from 'react'
4-
import {
5-
extractStyles as boxExtractStyles,
4+
import { DownshiftProps } from 'downshift'
5+
import { TransitionProps, TransitionStatus } from 'react-transition-group/Transition'
6+
import { extractStyles as boxExtractStyles, BoxProps, BoxComponent, PolymorphicBoxProps } from 'ui-box'
7+
/**
8+
* Generated types that are used for composition in manually written types need to be imported to be resolved
9+
*/
10+
import type { PaneOwnProps } from './types'
11+
12+
export type {
613
BoxProps,
14+
BoxOwnProps,
715
BoxComponent,
816
PolymorphicBoxProps,
17+
EnhancerProps,
918
BoxCssProps,
1019
CssProps
1120
} from 'ui-box'
12-
import { DownshiftProps } from 'downshift'
13-
import { TransitionProps, TransitionStatus } from 'react-transition-group/Transition'
21+
export { configureSafeHref } from 'ui-box'
1422

15-
export { configureSafeHref, BoxProps, BoxOwnProps, BoxComponent, PolymorphicBoxProps, EnhancerProps } from 'ui-box'
23+
/**
24+
* Re-export generated types through this manually written typedef file until we can point to the generated index.d.ts file
25+
*/
26+
export type { PaneProps, PaneOwnProps } from './types'
27+
28+
/**
29+
* Re-export generated types through this manually written typedef file until we can point to the generated index.d.ts file
30+
*/
31+
export { Pane } from './types'
1632

1733
// Re-exporting these utility types for testing + consumer usage if needed
1834
export type Pick<T, Properties extends keyof T> = { [Key in Properties]: T[Key] }
@@ -319,13 +335,11 @@ type TokenizableProps = 'elevation' | 'fontWeight' | 'zIndex'
319335
type PolymorphicBoxPropsOrTokens<T extends Components = Components> = Omit<
320336
PolymorphicBoxProps<BaseHTMLElement<T>>,
321337
TokenizableProps
322-
> &
323-
{ [key in TokenizableProps]?: string }
338+
> & { [key in TokenizableProps]?: string }
324339

325340
export type StyleProps<T extends Components = Components> = {
326341
[key in ComponentPseudoSelectors<T>]: PolymorphicBoxPropsOrTokens<T>
327-
} &
328-
PolymorphicBoxPropsOrTokens<T>
342+
} & PolymorphicBoxPropsOrTokens<T>
329343

330344
export type ComponentStyle<T extends Components = Components> = {
331345
baseStyle?: Partial<StyleProps<T>>
@@ -526,9 +540,7 @@ export interface AutocompleteProps extends Omit<DownshiftProps<any>, 'children'>
526540
toggle: () => void
527541
getRef: React.Ref<any>
528542
isShown: NonNullable<PopoverProps['isShown']>
529-
getInputProps: <T>(
530-
options?: T
531-
) => T & {
543+
getInputProps: <T>(options?: T) => T & {
532544
onChange: (event: React.ChangeEvent) => void
533545
onKeyDown: (event: React.KeyboardEvent) => void
534546
onBlur: (event: React.FocusEvent) => void
@@ -1466,21 +1478,6 @@ export declare const Menu: React.FC<MenuProps> & {
14661478
OptionsGroup: typeof MenuOptionsGroup
14671479
}
14681480

1469-
export interface PaneOwnProps {
1470-
background?: string
1471-
border?: boolean | string
1472-
borderTop?: boolean | string
1473-
borderRight?: boolean | string
1474-
borderBottom?: boolean | string
1475-
borderLeft?: boolean | string
1476-
elevation?: Elevation
1477-
hoverElevation?: Elevation
1478-
activeElevation?: Elevation
1479-
}
1480-
1481-
export type PaneProps = PolymorphicBoxProps<'div', PaneOwnProps>
1482-
export declare const Pane: BoxComponent<PaneOwnProps, 'div'>
1483-
14841481
export interface PaginationOwnProps {
14851482
/**
14861483
* The current page that a user is on - defaults to 1.
@@ -2752,9 +2749,7 @@ export function majorScale(x: number): number
27522749

27532750
export function minorScale(x: number): number
27542751

2755-
export function extractStyles(options?: {
2756-
nonce?: React.ScriptHTMLAttributes<'script'>['nonce']
2757-
}): {
2752+
export function extractStyles(options?: { nonce?: React.ScriptHTMLAttributes<'script'>['nonce'] }): {
27582753
css: string
27592754
cache: {
27602755
uiBoxCache: ReturnType<typeof boxExtractStyles>['cache']

package.json

Lines changed: 35 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,17 @@
2828
"esm",
2929
"umd",
3030
"index.d.ts",
31-
"codemods/dist"
31+
"codemods/dist",
32+
"types"
3233
],
3334
"sideEffects": false,
3435
"scripts": {
35-
"build": "yarn generate-icons && concurrently --names 'commonjs,esm,umd,codemods' 'yarn build-commonjs' 'yarn build-esm' 'yarn build-umd' 'yarn build-codemods'",
36+
"build": "yarn generate-icons && concurrently --names 'commonjs,esm,umd,codemods,types' 'yarn build-commonjs' 'yarn build-esm' 'yarn build-umd' 'yarn build-codemods' 'yarn build-types'",
3637
"build-codemods": "cd codemods && yarn build",
37-
"build-commonjs": "BABEL_ENV=commonjs babel src --out-dir commonjs --ignore '**/stories','**/test'",
38-
"build-esm": "BABEL_ENV=esm babel src --out-dir esm --ignore '**/stories','**/test'",
38+
"build-commonjs": "tsc --project tsconfig.commonjs.json",
39+
"build-esm": "BABEL_ENV=esm babel src --out-dir esm --ignore '**/stories','**/test','**/__tests__','**/types' --extensions '.js,.ts,.tsx'",
3940
"build-storybook": "build-storybook",
41+
"build-types": "tsc --project tsconfig.types.json",
4042
"build-umd": "rollup -c",
4143
"chromatic": "npx chromatic",
4244
"clean": "git clean -Xdf",
@@ -45,14 +47,16 @@
4547
"deploy-docs": "cd docs && yarn install && yarn deploy",
4648
"dev": "start-storybook -p 6006",
4749
"generate-icons": "./tools/generate-icons.js",
48-
"lint": "eslint \"src/**/*.js\" --cache",
50+
"lint": "eslint \"src/**/*.{js,ts,tsx}\" --cache",
4951
"postpublish": "branch=$(git rev-parse --symbolic-full-name --abbrev-ref HEAD); if [[ $branch == \"master\" ]]; then yarn update-docs || yarn deploy-docs; else echo \"not on main branch, skipping docs deploy\"; fi;",
50-
"prepublishOnly": "rm -rf esm commonjs umd && yarn build",
52+
"prebuild": "yarn typecheck",
53+
"prepublishOnly": "rm -rf esm commonjs umd types && yarn build",
5154
"release": "np",
5255
"size": "size-limit",
5356
"storybook": "start-storybook -p 6006",
5457
"test": "yarn lint && yarn tsd && yarn jest",
5558
"test:watch": "yarn jest --watch",
59+
"typecheck": "tsc --noEmit",
5660
"update-docs": "cd docs && yarn add evergreen-ui@latest --exact && git add package.json yarn.lock && git show-branch --no-name HEAD | grep -E 'v[0-9]+.[0-9]+.[0-9]+' && git commit --amend --no-edit || git commit -m \"Updated doc site evergreen version\""
5761
},
5862
"engines": {
@@ -61,7 +65,6 @@
6165
"dependencies": {
6266
"@babel/runtime": "^7.1.2",
6367
"@segment/react-tiny-virtual-list": "^2.2.1",
64-
"@types/react": "^16.9.5",
6568
"@types/react-transition-group": "^4.4.0",
6669
"arrify": "^1.0.1",
6770
"downshift": "^5.2.0",
@@ -92,6 +95,7 @@
9295
"@babel/plugin-transform-runtime": "^7.1.0",
9396
"@babel/preset-env": "^7.1.0",
9497
"@babel/preset-react": "^7.0.0",
98+
"@babel/preset-typescript": "^7.18.6",
9599
"@babel/register": "^7.0.0",
96100
"@blueprintjs/icons": "^3.31.0",
97101
"@faker-js/faker": "^6.1.2",
@@ -100,6 +104,7 @@
100104
"@rollup/plugin-commonjs": "^15.1.0",
101105
"@rollup/plugin-node-resolve": "^9.0.0",
102106
"@rollup/plugin-replace": "^2.3.3",
107+
"@rollup/plugin-typescript": "^10.0.1",
103108
"@size-limit/preset-big-lib": "^4.5.4",
104109
"@storybook/addon-essentials": "^6.0.21",
105110
"@storybook/addon-options": "^5.3.21",
@@ -109,8 +114,22 @@
109114
"@testing-library/jest-dom": "^5.11.6",
110115
"@testing-library/react": "13.3.0",
111116
"@testing-library/user-event": "^13.1.9",
117+
"@types/fs-extra": "^9.0.13",
118+
"@types/fuzzaldrin-plus": "^0.6.2",
119+
"@types/humanize-plus": "1.8.0",
120+
"@types/jest": "27.4.0",
121+
"@types/lodash.debounce": "^4.0.6",
122+
"@types/lodash.differencewith": "^4.5.6",
123+
"@types/lodash.isempty": "^4.4.6",
124+
"@types/lodash.merge": "^4.6.6",
125+
"@types/lodash.uniqby": "^4.7.6",
126+
"@types/node": "^17.0.21",
127+
"@types/react-is": "17.0.3",
128+
"@types/testing-library__jest-dom": "5.14.3",
129+
"@types/tinycolor2": "^1.4.3",
130+
"@typescript-eslint/eslint-plugin": "^5.14.0",
131+
"@typescript-eslint/parser": "^5.14.0",
112132
"babel-core": "7.0.0-bridge.0",
113-
"babel-eslint": "^10.0.1",
114133
"babel-loader": "^8.1.0",
115134
"babel-plugin-add-react-displayname": "^0.0.5",
116135
"camelcase": "^5.0.0",
@@ -132,7 +151,7 @@
132151
"jest": "^26.4.2",
133152
"lint-staged": "^10.0.1",
134153
"np": "^6.3.2",
135-
"prettier": "^1.14.3",
154+
"prettier": "2.8.1",
136155
"react": "^18.2.0",
137156
"react-dom": "^18.2.0",
138157
"react-is": "^18.2.0",
@@ -142,6 +161,7 @@
142161
"size-limit": "^4.5.0",
143162
"starwars-names": "^1.6.0",
144163
"tsd": "^0.19.1",
164+
"typescript": "4.9.4",
145165
"url-loader": "^1.1.2",
146166
"webpack": "^4.43.0",
147167
"yarnhook": "^0.5.1"
@@ -154,14 +174,16 @@
154174
"singleQuote": true,
155175
"printWidth": 120,
156176
"tabWidth": 2,
157-
"useTabs": false
177+
"useTabs": false,
178+
"trailingComma": "none",
179+
"arrowParens": "avoid"
158180
},
159181
"lint-staged": {
160-
"!(codemods|docs)/**/*.js": [
182+
"!(codemods|docs)/**/.{js,ts,tsx}": [
161183
"yarn lint --fix",
162184
"prettier --write"
163185
],
164-
"docs/**/*.{ts,tsx,js,jsx}": [
186+
"docs/**/*.{js,ts,tsx}": [
165187
"yarn --cwd ./docs run lint"
166188
],
167189
"*.{json,md}": [
@@ -179,7 +201,7 @@
179201
"<rootDir>/commonjs/"
180202
],
181203
"collectCoverageFrom": [
182-
"src/**/*.{js,jsx}",
204+
"src/**/*.{js,ts,tsx}",
183205
"!**/*.stories.{js,jsx}",
184206
"!src/{constants,test,themes}/**",
185207
"!src/icons/generated/**"

rollup.config.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import babel from '@rollup/plugin-babel'
22
import commonjs from '@rollup/plugin-commonjs'
33
import resolve from '@rollup/plugin-node-resolve'
44
import replace from '@rollup/plugin-replace'
5+
import typescript from '@rollup/plugin-typescript'
56
import { terser } from 'rollup-plugin-terser'
67
import pkg from './package.json'
78

@@ -24,7 +25,7 @@ const globals = {
2425
export default [
2526
// UMD Development
2627
{
27-
input: 'src/index.js',
28+
input: 'src/index.ts',
2829
external,
2930
output: {
3031
file: 'umd/evergreen.js',
@@ -42,6 +43,7 @@ export default [
4243
}
4344
}),
4445
resolve(),
46+
typescript({ compilerOptions: { module: 'esnext', outDir: 'umd' } }),
4547
commonjs({
4648
include: 'node_modules/**'
4749
}),
@@ -53,7 +55,7 @@ export default [
5355
},
5456
// UMD Production
5557
{
56-
input: 'src/index.js',
58+
input: 'src/index.ts',
5759
external,
5860
output: {
5961
file: 'umd/evergreen.min.js',
@@ -71,6 +73,7 @@ export default [
7173
}
7274
}),
7375
resolve(),
76+
typescript({ compilerOptions: { module: 'esnext', outDir: 'umd' } }),
7477
commonjs({
7578
include: 'node_modules/**'
7679
}),

src/file-uploader/src/utils/rebase-files.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import splitFiles from './split-files'
1111
/**
1212
* @typedef {object} RebaseFilesResult
1313
* @property {File[]} accepted
14-
* @property {FileRejection[]} rejected
14+
* @property {import('./get-file-rejections').FileRejection[]} rejected
1515
*/
1616

1717
/**

src/file-uploader/src/utils/split-files.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import getFileRejections from './get-file-rejections'
1212
/**
1313
* @typedef {object} SplitFilesResult
1414
* @property {File[]} accepted
15-
* @property {FileRejection[]} rejected
15+
* @property {import('./get-file-rejections').FileRejection[]} rejected
1616
*/
1717

1818
/**

0 commit comments

Comments
 (0)