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

Commit faf6398

Browse files
committed
fix: remove tsc compiler warnings
1 parent 9e58939 commit faf6398

File tree

16 files changed

+64
-115
lines changed

16 files changed

+64
-115
lines changed

README.md

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
</p>
2626

2727
<p>
28-
<a href="#key-features">Key features</a> •
2928
<a href="#install">Install</a> •
3029
<a href="#example-usage">Example usage</a> •
3130
<a href="#why">Why?</a> •
@@ -38,13 +37,6 @@
3837

3938
</div>
4039

41-
## Key features
42-
43-
* __Blazing fast!__
44-
* __Small bundle size!__
45-
* __Typescript definition files!__
46-
* __Above 90% test coverage!__
47-
4840
## Install
4941

5042
```bash

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@
77
"type": "git",
88
"url": "https://github.com/csvenke/react-semantics.git"
99
},
10-
"main": "index.js",
11-
"module": "index.es.js",
10+
"main": "index.cjs.js",
11+
"module": "index.esm.js",
1212
"types": "types/index.d.ts",
1313
"files": [
14-
"index.js",
15-
"index.es.js",
14+
"index.cjs.js",
15+
"index.esm.js",
1616
"types/index.d.ts",
1717
"types/components"
1818
],
@@ -22,7 +22,9 @@
2222
"react",
2323
"react-components",
2424
"react-utils",
25-
"react-library"
25+
"react-library",
26+
"react-component-library",
27+
"semantic"
2628
],
2729
"dependencies": {
2830
"prop-types": "^15.6.2"
@@ -78,15 +80,16 @@
7880
"docs:server": "styleguidist server",
7981
"docs": "styleguidist build",
8082
"lint:fix": "npm run lint:write --fix \"src/**/*.{ts,tsx}\"",
81-
"lint:write": "tslint -c tslint.json",
83+
"lint:write": "tslint -p tsconfig.build.json -c tslint.json",
8284
"lint": "npm run lint:write \"src/**/*.{ts,tsx}\"",
8385
"prettier:write": "prettier -c .prettierrc --write",
8486
"prettier": "npm run prettier:write \"src/**/*.{ts,tsx}\"",
8587
"publish:lib": "npm run build && cd lib && npm publish && cd ..",
8688
"report-coverage": "cat ./coverage/lcov.info | coveralls",
8789
"test:prod": "npm run lint && npm run test --coverage --no-cache",
8890
"test:watch": "jest --watch",
89-
"test": "jest"
91+
"test": "jest",
92+
"tslint:check": "tslint-config-prettier-check ./tslint.json"
9093
},
9194
"husky": {
9295
"hooks": {

rollup.config.js

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,10 @@ import { uglify } from 'rollup-plugin-uglify';
33
import { terser } from 'rollup-plugin-terser';
44
import pkg from './package.json';
55

6-
const externals = [
7-
...(Object.keys(pkg.dependencies) || {}),
8-
...(Object.keys(pkg.peerDependencies) || {}),
9-
];
10-
116
const createConfig = ({ output, plugins } = {}) => ({
127
input: 'src/index.ts',
138
output,
14-
external: externals,
9+
external: ['react', 'prop-types'],
1510
plugins: [
1611
typescript({
1712
useTsconfigDeclarationDir: true,
@@ -24,11 +19,11 @@ const createConfig = ({ output, plugins } = {}) => ({
2419

2520
export default [
2621
createConfig({
27-
output: { file: 'lib/index.js', format: 'cjs' },
22+
output: { file: `lib/${pkg.main}`, format: 'cjs' },
2823
plugins: [uglify()],
2924
}),
3025
createConfig({
31-
output: { file: 'lib/index.es.js', format: 'es' },
26+
output: { file: `lib/${pkg.module}`, format: 'es' },
3227
plugins: [terser()],
3328
}),
3429
];

src/components/List/List.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import * as PropTypes from 'prop-types';
22
import * as React from 'react';
33

4-
type ListItemCallbackFn = (
4+
export type ListItemCallbackFn = (
55
value?: any,
66
index?: number,
77
array?: any[],

src/components/Resolve/Resolve.tsx

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,41 @@
11
import * as PropTypes from 'prop-types';
22
import * as React from 'react';
3-
import { isPromise } from '../../utils';
43

54
export interface IResolveProps {
65
/** The promise. */
7-
promise?: Promise<any>;
6+
promise: Promise<any>;
87

98
/** Returns content when promise is resolved. */
10-
resolved?: (value) => React.ReactNode;
9+
resolved?: (value: any) => React.ReactNode;
1110

1211
/** Returns content while promise is being handled. */
1312
pending?: React.ReactNode;
1413

1514
/** Returns content when promise is rejected. */
16-
rejected?: (error) => React.ReactNode;
15+
rejected?: (error: any) => React.ReactNode;
1716
}
1817

19-
const statusTypes = {
18+
export const statusTypes = {
2019
none: 'none',
2120
pending: 'pending',
2221
rejected: 'rejected',
2322
resolved: 'resolved',
2423
};
2524

26-
const initialState = {
25+
export const initialState = {
2726
status: statusTypes.none,
2827
value: '',
2928
};
3029

31-
type IResolveState = Readonly<typeof initialState>;
30+
export type IResolveState = Readonly<typeof initialState>;
3231

3332
/**
3433
* Semantic helper component that returns content based on the status of the specified promise.
3534
*/
3635
class Resolve extends React.Component<IResolveProps, IResolveState> {
3736
public static propTypes = {
3837
pending: PropTypes.oneOfType([PropTypes.func, PropTypes.node]),
39-
promise: isPromise,
38+
promise: PropTypes.instanceOf(Promise).isRequired,
4039
rejected: PropTypes.func,
4140
resolved: PropTypes.func,
4241
};
@@ -52,7 +51,7 @@ class Resolve extends React.Component<IResolveProps, IResolveState> {
5251
this.handlePromise(this.props.promise);
5352
}
5453

55-
public componentDidUpdate(prevProps) {
54+
public componentDidUpdate(prevProps: IResolveProps) {
5655
if (this.props.promise !== prevProps.promise) {
5756
this.setState({
5857
status: statusTypes.none,
@@ -95,7 +94,7 @@ class Resolve extends React.Component<IResolveProps, IResolveState> {
9594
}
9695

9796
// Promise resolver function
98-
private handlePromise(promise) {
97+
private handlePromise(promise: Promise<any>) {
9998
// Store the current promise to fast exit if promise is change during handling
10099
const currentPromise = promise;
101100
this.setState({

src/components/Switch/Switch.tsx

Lines changed: 24 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@ import * as React from 'react';
44
import SwitchCase, { ISwitchCaseProps } from './SwitchCase';
55
import SwitchDefault, { ISwitchDefaultProps } from './SwitchDefault';
66

7-
type SwitchChildProps = ISwitchCaseProps & ISwitchDefaultProps;
8-
7+
export { ISwitchDefaultProps, ISwitchCaseProps };
98
export interface ISwitchProps {
109
/** Conditional statement. */
1110
value: any;
@@ -30,23 +29,20 @@ class Switch extends React.Component<ISwitchProps> {
3029

3130
public render() {
3231
const switchValue = this.props.value;
33-
let match;
34-
let child;
32+
let match: boolean | undefined;
33+
let child: any;
3534

36-
React.Children.forEach(
37-
this.props.children,
38-
(element: React.ReactElement<SwitchChildProps>) => {
39-
if (
40-
match === undefined &&
41-
React.isValidElement(element) &&
42-
this.isValidChild(element)
43-
) {
44-
const caseValue = element.props.value;
45-
child = element;
46-
match = caseValue === switchValue || undefined;
47-
}
48-
},
49-
);
35+
React.Children.forEach(this.props.children, element => {
36+
if (
37+
match === undefined &&
38+
React.isValidElement(element) &&
39+
this.isValidChild(element)
40+
) {
41+
const caseValue = this.getElementValue(element);
42+
child = element;
43+
match = caseValue === switchValue || undefined;
44+
}
45+
});
5046

5147
// No match found, return default if it exists.
5248
if (!match && this.isSwitchDefault(child)) {
@@ -57,15 +53,22 @@ class Switch extends React.Component<ISwitchProps> {
5753
return match ? React.cloneElement(child) : null;
5854
}
5955

60-
private isValidChild = child => {
56+
private getElementValue = (element: any) => {
57+
if (element && element.props) {
58+
return element.props.value;
59+
}
60+
return undefined;
61+
};
62+
63+
private isValidChild = (child: any) => {
6164
return this.isSwitchCase(child) || this.isSwitchDefault(child);
6265
};
6366

64-
private isSwitchCase = child => {
67+
private isSwitchCase = (child: any) => {
6568
return child.type.prototype === SwitchCase.prototype;
6669
};
6770

68-
private isSwitchDefault = child => {
71+
private isSwitchDefault = (child: any) => {
6972
return child.type.prototype === SwitchDefault.prototype;
7073
};
7174
}

src/components/Switch/SwitchCase.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ export interface ISwitchCaseProps {
1616

1717
/**
1818
* Semantic helper component that can be accessed from the `Switch` component.
19-
* Only ment to be used inside the children of the `Switch` component.
2019
*/
2120
const SwitchCase: React.SFC<ISwitchCaseProps> = ({ value, render, children }) => {
2221
if (value !== undefined) {

src/components/Switch/SwitchDefault.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ export interface ISwitchDefaultProps {
1313

1414
/**
1515
* Semantic helper component that can be accessed from the `Switch` component.
16-
* Only ment to be used inside the children of the `Switch` component.
1716
*/
1817
const SwitchDefault: React.SFC<ISwitchDefaultProps> = ({ render, children }) => {
1918
const value = '__SWITCH_CASE_VALUE_OVERRIDE_USE_THIS_AND_YOU_WILL_BE_FIRED__';

src/utils/index.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
1-
export * from './isEmptyChildren/isEmptyChildren';
2-
export * from './isPromise/isPromise';
1+
export { default as isEmptyChildren } from './isEmptyChildren/isEmptyChildren';

0 commit comments

Comments
 (0)