Skip to content

Commit 39660b6

Browse files
authored
Merge pull request #14 from openscript/develop
Enhance typing
2 parents 103b4ef + 90a2473 commit 39660b6

File tree

7 files changed

+55
-51
lines changed

7 files changed

+55
-51
lines changed

package.json

+3-3
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
"react"
88
],
99
"homepage": "https://openscript.github.io/react-dsv-import/",
10-
"version": "0.3.1",
10+
"version": "0.3.2",
1111
"main": "dist/index.js",
1212
"module": "dist/es/index.js",
1313
"types": "dist/index.d.ts",
@@ -32,8 +32,8 @@
3232
"@types/node": "^14.0.5",
3333
"@types/react": "^16.9.35",
3434
"@types/react-dom": "^16.9.8",
35-
"@typescript-eslint/eslint-plugin": "^3.0.0",
36-
"@typescript-eslint/parser": "^3.0.0",
35+
"@typescript-eslint/eslint-plugin": "^3.0.1",
36+
"@typescript-eslint/parser": "^3.0.1",
3737
"babel-loader": "^8.1.0",
3838
"babel-preset-react-app": "^9.1.2",
3939
"eslint": "^7.1.0",

src/DSVImport.tsx

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import React, { PropsWithChildren, useReducer, useEffect } from 'react';
2-
import { ColumnType } from './models/column';
2+
import { ColumnType, GenericColumnType } from './models/column';
33
import { getDSVImportContext, useDSVImport, createReducer } from './features/context';
44
import { createParserMiddleware } from './middlewares/parserMiddleware';
55
import { State } from './models/state';
@@ -14,7 +14,7 @@ interface EventListenerProps<T> {
1414
onValidation?: (errors: ValidationError<T>[]) => void;
1515
}
1616

17-
const EventListener = <T extends { [key: string]: string }>(props: EventListenerProps<T>) => {
17+
const EventListener = <T extends GenericColumnType>(props: EventListenerProps<T>) => {
1818
const [context] = useDSVImport<T>();
1919

2020
useEffect(() => {
@@ -39,7 +39,7 @@ export interface Props<T> {
3939
transformers?: Transformer[];
4040
}
4141

42-
export const DSVImport = <T extends { [key: string]: string }>(props: PropsWithChildren<Props<T>>) => {
42+
export const DSVImport = <T extends GenericColumnType>(props: PropsWithChildren<Props<T>>) => {
4343
const DSVImportContext = getDSVImportContext<T>();
4444
const initialValues: State<T> = { columns: props.columns, transformers: props.transformers };
4545
const [state, dispatch] = useReducer(createReducer<T>(), initialValues);

src/features/context.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { State, emptyState } from '../models/state';
22
import { createContext, Dispatch, useContext } from 'react';
33
import { Actions } from '../models/actions';
4+
import { GenericColumnType } from '../models/column';
45

56
export const reducer = <T>(state: State<T>, action: Actions<T>) => {
67
switch (action.type) {
@@ -34,4 +35,4 @@ export const getDSVImportContext = <T>() => {
3435
}
3536
return contextSingleton as React.Context<[State<T>, Dispatch<Actions<T>>]>;
3637
};
37-
export const useDSVImport = <T = { [key: string]: string }>() => useContext(getDSVImportContext<T>());
38+
export const useDSVImport = <T = GenericColumnType>() => useContext(getDSVImportContext<T>());

src/index.tsx

+6-4
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,18 @@
1+
import { PropsWithChildren } from 'react';
2+
import { DSVImport as Import, Props } from './DSVImport';
3+
import { GenericColumnType } from './models/column';
14
import { TextareaInput } from './components/inputs/TextareaInput';
25
import { TablePreview } from './components/previews/TablePreview';
3-
import { DSVImport as Import, Props } from './DSVImport';
4-
import { PropsWithChildren } from 'react';
56

6-
export function DSVImport<T extends { [key: string]: string }>(props: PropsWithChildren<Props<T>>) {
7+
export function DSVImport<T extends GenericColumnType>(props: PropsWithChildren<Props<T>>) {
78
return Import<T>(props);
89
}
910

1011
DSVImport.TextareaInput = TextareaInput;
1112
DSVImport.TablePreview = TablePreview;
1213

13-
export { ColumnType } from './models/column';
14+
export { ColumnType, GenericColumnType } from './models/column';
1415
export { useDSVImport } from './features/context';
1516
export { Rule } from './models/rule';
1617
export { Transformer } from './models/transformer';
18+
export { ValidationError } from './models/validation';

src/models/column.ts

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { Rule } from './rule';
22
import { Transformer } from './transformer';
33

4+
export type GenericColumnType = { [key: string]: string };
45
export type ColumnType<T> = { key: keyof T; label: string; rules?: Rule[]; transformers?: Transformer[] };

src/models/state.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { ColumnType } from './column';
1+
import { ColumnType, GenericColumnType } from './column';
22
import { ValidationError } from './validation';
33
import { Transformer } from './transformer';
44

@@ -10,6 +10,6 @@ export interface State<T> {
1010
columns: ColumnType<T>[];
1111
}
1212

13-
export const emptyState: State<{ [key: string]: string }> = {
13+
export const emptyState: State<GenericColumnType> = {
1414
columns: []
1515
};

yarn.lock

+38-38
Original file line numberDiff line numberDiff line change
@@ -2135,9 +2135,9 @@
21352135
loader-utils "^1.2.3"
21362136

21372137
"@testing-library/dom@^7.2.2":
2138-
version "7.5.7"
2139-
resolved "https://registry.yarnpkg.com/@testing-library/dom/-/dom-7.5.7.tgz#c4bf683a65083d4a78644588cfa4ad684c113fc7"
2140-
integrity sha512-835MiwAxQE7xjSrhpeJbv41UQRmsPJQ0tGfzWiJMdZj2LBbdG5cT8Z44Viv11/XucCmJHr/v8q7VpZnuSimscg==
2138+
version "7.5.8"
2139+
resolved "https://registry.yarnpkg.com/@testing-library/dom/-/dom-7.5.8.tgz#35eb20f1cfd90629a09728954fd916ea142e5de5"
2140+
integrity sha512-aEK4GDeIk3sHuuF8NNvZrmZg5xfF7llvdlVfjely/fPg/GE4yLa0cVZEBWpS6oVUBk2tEXjwTDPFnMOe/M0GTQ==
21412141
dependencies:
21422142
"@babel/runtime" "^7.9.6"
21432143
aria-query "^4.0.2"
@@ -2485,41 +2485,41 @@
24852485
dependencies:
24862486
"@types/yargs-parser" "*"
24872487

2488-
"@typescript-eslint/eslint-plugin@^3.0.0":
2489-
version "3.0.0"
2490-
resolved "https://registry.yarnpkg.com/@typescript-eslint/eslint-plugin/-/eslint-plugin-3.0.0.tgz#02f8ec6b5ce814bda80dfc22463f108bed1f699b"
2491-
integrity sha512-lcZ0M6jD4cqGccYOERKdMtg+VWpoq3NSnWVxpc/AwAy0zhkUYVioOUZmfNqiNH8/eBNGhCn6HXd6mKIGRgNc1Q==
2488+
"@typescript-eslint/eslint-plugin@^3.0.1":
2489+
version "3.0.1"
2490+
resolved "https://registry.yarnpkg.com/@typescript-eslint/eslint-plugin/-/eslint-plugin-3.0.1.tgz#368fe7d4c3d927e9fd27b7ba150b4b7e83ddfabe"
2491+
integrity sha512-RxGldRQD3hgOK2xtBfNfA5MMV3rn5gVChe+MIf14hKm51jO2urqF64xOyVrGtzThkrd4rS1Kihqx2nkSxkXHvA==
24922492
dependencies:
2493-
"@typescript-eslint/experimental-utils" "3.0.0"
2493+
"@typescript-eslint/experimental-utils" "3.0.1"
24942494
functional-red-black-tree "^1.0.1"
24952495
regexpp "^3.0.0"
24962496
semver "^7.3.2"
24972497
tsutils "^3.17.1"
24982498

2499-
"@typescript-eslint/[email protected].0":
2500-
version "3.0.0"
2501-
resolved "https://registry.yarnpkg.com/@typescript-eslint/experimental-utils/-/experimental-utils-3.0.0.tgz#1ddf53eeb61ac8eaa9a77072722790ac4f641c03"
2502-
integrity sha512-BN0vmr9N79M9s2ctITtChRuP1+Dls0x/wlg0RXW1yQ7WJKPurg6X3Xirv61J2sjPif4F8SLsFMs5Nzte0WYoTQ==
2499+
"@typescript-eslint/[email protected].1":
2500+
version "3.0.1"
2501+
resolved "https://registry.yarnpkg.com/@typescript-eslint/experimental-utils/-/experimental-utils-3.0.1.tgz#e2721c970068fabd6621709234809c98cd3343ad"
2502+
integrity sha512-GdwOVz80MOWxbc/br1DC30eeqlxfpVzexHgHtf3L0hcbOu1xAs1wSCNcaBTLMOMZbh1gj/cKZt0eB207FxWfFA==
25032503
dependencies:
25042504
"@types/json-schema" "^7.0.3"
2505-
"@typescript-eslint/typescript-estree" "3.0.0"
2505+
"@typescript-eslint/typescript-estree" "3.0.1"
25062506
eslint-scope "^5.0.0"
25072507
eslint-utils "^2.0.0"
25082508

2509-
"@typescript-eslint/parser@^3.0.0":
2510-
version "3.0.0"
2511-
resolved "https://registry.yarnpkg.com/@typescript-eslint/parser/-/parser-3.0.0.tgz#fe9fdf18a1155c02c04220c14506a320cb6c6944"
2512-
integrity sha512-8RRCA9KLxoFNO0mQlrLZA0reGPd/MsobxZS/yPFj+0/XgMdS8+mO8mF3BDj2ZYQj03rkayhSJtF1HAohQ3iylw==
2509+
"@typescript-eslint/parser@^3.0.1":
2510+
version "3.0.1"
2511+
resolved "https://registry.yarnpkg.com/@typescript-eslint/parser/-/parser-3.0.1.tgz#f5163e3a789422f5c62f4daf822bfa03b7e4472d"
2512+
integrity sha512-Pn2tDmOc4Ri93VQnT70W0pqQr6i/pEZqIPXfWXm4RuiIprL0t6SG13ViVXHgfScknL2Fm2G4IqXhUzxSRCWXCw==
25132513
dependencies:
25142514
"@types/eslint-visitor-keys" "^1.0.0"
2515-
"@typescript-eslint/experimental-utils" "3.0.0"
2516-
"@typescript-eslint/typescript-estree" "3.0.0"
2515+
"@typescript-eslint/experimental-utils" "3.0.1"
2516+
"@typescript-eslint/typescript-estree" "3.0.1"
25172517
eslint-visitor-keys "^1.1.0"
25182518

2519-
"@typescript-eslint/[email protected].0":
2520-
version "3.0.0"
2521-
resolved "https://registry.yarnpkg.com/@typescript-eslint/typescript-estree/-/typescript-estree-3.0.0.tgz#fa40e1b76ccff880130be054d9c398e96004bf42"
2522-
integrity sha512-nevQvHyNghsfLrrByzVIH4ZG3NROgJ8LZlfh3ddwPPH4CH7W4GAiSx5qu+xHuX5pWsq6q/eqMc1io840ZhAnUg==
2519+
"@typescript-eslint/[email protected].1":
2520+
version "3.0.1"
2521+
resolved "https://registry.yarnpkg.com/@typescript-eslint/typescript-estree/-/typescript-estree-3.0.1.tgz#8c0cfb7cda64bd6f54185a7b7d1923d25d36b2a8"
2522+
integrity sha512-FrbMdgVCeIGHKaP9OYTttFTlF8Ds7AkjMca2GzYCE7pVch10PAJc1mmAFt+DfQPgu/2TrLAprg2vI0PK/WTdcg==
25232523
dependencies:
25242524
debug "^4.1.1"
25252525
eslint-visitor-keys "^1.1.0"
@@ -3933,9 +3933,9 @@ can-use-dom@^0.1.0:
39333933
integrity sha1-IsxKNKCrxDlQ9CxkEQJKP2NmtFo=
39343934

39353935
caniuse-lite@^1.0.30000989, caniuse-lite@^1.0.30001043, caniuse-lite@^1.0.30001061:
3936-
version "1.0.30001065"
3937-
resolved "https://registry.yarnpkg.com/caniuse-lite/-/caniuse-lite-1.0.30001065.tgz#e8d7fef61cdfd8a7107493ad6bf551a4eb59c68f"
3938-
integrity sha512-DDxCLgJ266YnAHQv0jS1wdOaihRFF52Zgmlag39sQJVy2H46oROpJp4hITstqhdB8qnHSrKNoAEkQA9L/oYF9A==
3936+
version "1.0.30001066"
3937+
resolved "https://registry.yarnpkg.com/caniuse-lite/-/caniuse-lite-1.0.30001066.tgz#0a8a58a10108f2b9bf38e7b65c237b12fd9c5f04"
3938+
integrity sha512-Gfj/WAastBtfxLws0RCh2sDbTK/8rJuSeZMecrSkNGYxPcv7EzblmDGfWQCFEQcSqYE2BRgQiJh8HOD07N5hIw==
39393939

39403940
capture-exit@^2.0.0:
39413941
version "2.0.0"
@@ -4502,9 +4502,9 @@ [email protected], cross-spawn@^6.0.0:
45024502
which "^1.2.9"
45034503

45044504
cross-spawn@^7.0.0, cross-spawn@^7.0.2:
4505-
version "7.0.2"
4506-
resolved "https://registry.yarnpkg.com/cross-spawn/-/cross-spawn-7.0.2.tgz#d0d7dcfa74e89115c7619f4f721a94e1fdb716d6"
4507-
integrity sha512-PD6G8QG3S4FK/XCGFbEQrDqO2AnMMsy0meR7lerlIOHAAbkuavGU/pOqprrlvfTNjvowivTeBsjebAL0NSoMxw==
4505+
version "7.0.3"
4506+
resolved "https://registry.yarnpkg.com/cross-spawn/-/cross-spawn-7.0.3.tgz#f73a85b9d5d41d045551c177e2882d4ac85728a6"
4507+
integrity sha512-iRDPJKUPVEND7dHPO8rkbOnPpyDygcDFtWjpeWNCgy8WP2rXcxXL8TskReQl6OrB2G7+UJrags1q15Fudc7G6w==
45084508
dependencies:
45094509
path-key "^3.1.0"
45104510
shebang-command "^2.0.0"
@@ -5022,9 +5022,9 @@ ejs@^2.7.4:
50225022
integrity sha512-7vmuyh5+kuUyJKePhQfRQBhXV5Ce+RnaeeQArKu1EAMpL3WbgMt5WG6uQZpEVvYSSsxMXRKOewtDk9RaTKXRlA==
50235023

50245024
electron-to-chromium@^1.3.247, electron-to-chromium@^1.3.413:
5025-
version "1.3.451"
5026-
resolved "https://registry.yarnpkg.com/electron-to-chromium/-/electron-to-chromium-1.3.451.tgz#0c075af3e2f06d706670bde0279432802ca8c83f"
5027-
integrity sha512-2fvco0F2bBIgqzO8GRP0Jt/91pdrf9KfZ5FsmkYkjERmIJG585cFeFZV4+CO6oTmU3HmCTgfcZuEa7kW8VUh3A==
5025+
version "1.3.452"
5026+
resolved "https://registry.yarnpkg.com/electron-to-chromium/-/electron-to-chromium-1.3.452.tgz#ef6877702722471aa044a2429336cd450629934d"
5027+
integrity sha512-IdbjgCEqDvcU/1kUQa6C49I2NZOY3SBmU9Eus7mdFdJJBqn0Lg1Epfi/T4nqVcxTNBEGhcjwMhY1EysMBsXZrw==
50285028

50295029
element-resize-detector@^1.2.1:
50305030
version "1.2.1"
@@ -5812,9 +5812,9 @@ [email protected]:
58125812
worker-rpc "^0.1.0"
58135813

58145814
fork-ts-checker-webpack-plugin@^4.1.0:
5815-
version "4.1.4"
5816-
resolved "https://registry.yarnpkg.com/fork-ts-checker-webpack-plugin/-/fork-ts-checker-webpack-plugin-4.1.4.tgz#f0dc3ece19ec5b792d7b8ecd2a7f43509a5285ce"
5817-
integrity sha512-R0nTlZSyV0uCCzYe1kgR7Ve8mXyDvMm1pJwUFb6zzRVF5rTNb24G6gn2DFQy+W5aJYp2eq8aexpCOO+1SCyCSA==
5815+
version "4.1.5"
5816+
resolved "https://registry.yarnpkg.com/fork-ts-checker-webpack-plugin/-/fork-ts-checker-webpack-plugin-4.1.5.tgz#780d52c65183742d8c885fff42a9ec9ea7006672"
5817+
integrity sha512-nuD4IDqoOfkEIlS6shhjLGaLBDSNyVJulAlr5lFbPe0saGqlsTo+/HmhtIrs/cNLFtmaudL10byivhxr+Qhh4w==
58185818
dependencies:
58195819
"@babel/code-frame" "^7.5.5"
58205820
chalk "^2.4.1"
@@ -9216,9 +9216,9 @@ postcss-value-parser@^4.0.0, postcss-value-parser@^4.0.3, postcss-value-parser@^
92169216
integrity sha512-97DXOFbQJhk71ne5/Mt6cOu6yxsSfM0QGQyl0L25Gca4yGWEGJaig7l7gbCX623VqTBNGLRLaVUCnNkcedlRSQ==
92179217

92189218
postcss@^7.0.0, postcss@^7.0.14, postcss@^7.0.16, postcss@^7.0.26, postcss@^7.0.27, postcss@^7.0.30, postcss@^7.0.5, postcss@^7.0.6:
9219-
version "7.0.30"
9220-
resolved "https://registry.yarnpkg.com/postcss/-/postcss-7.0.30.tgz#cc9378beffe46a02cbc4506a0477d05fcea9a8e2"
9221-
integrity sha512-nu/0m+NtIzoubO+xdAlwZl/u5S5vi/y6BCsoL8D+8IxsD3XvBS8X4YEADNIVXKVuQvduiucnRv+vPIqj56EGMQ==
9219+
version "7.0.31"
9220+
resolved "https://registry.yarnpkg.com/postcss/-/postcss-7.0.31.tgz#332af45cb73e26c0ee2614d7c7fb02dfcc2bd6dd"
9221+
integrity sha512-a937VDHE1ftkjk+8/7nj/mrjtmkn69xxzJgRETXdAUU+IgOYPQNJF17haGWbeDxSyk++HA14UA98FurvPyBJOA==
92229222
dependencies:
92239223
chalk "^2.4.2"
92249224
source-map "^0.6.1"

0 commit comments

Comments
 (0)