Skip to content

Commit a33763d

Browse files
author
Robert S
committed
Update TypeScript to use optional-chaining and nullish-coalescing
1 parent 1ae442d commit a33763d

File tree

6 files changed

+191
-78
lines changed

6 files changed

+191
-78
lines changed

craco.config.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@ const path = require('path');
22

33
module.exports = function({ env, paths }) {
44
return {
5+
babel: {
6+
presets: [],
7+
plugins: ['@babel/plugin-proposal-optional-chaining', '@babel/plugin-proposal-nullish-coalescing-operator'],
8+
// loaderOptions: { /* Any babel-loader configuration options: https://github.com/babel/babel-loader. */ },
9+
// loaderOptions: (babelLoaderOptions, { env, paths }) => { return babelLoaderOptions; }
10+
},
511
webpack: {
612
alias: {
713
environment: path.join(__dirname, 'src', 'environments', process.env.CLIENT_ENV),

package.json

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
"name": "react-typescript",
33
"version": "0.1.0",
44
"private": true,
5+
"homepage": "https://codebelt.github.io/react-redux-architecture",
56
"husky": {
67
"hooks": {
78
"pre-commit": "pretty-quick --staged",
@@ -16,6 +17,8 @@
1617
"prod": "cross-env CLIENT_ENV=production craco start",
1718
"---------- PRODUCTION ----------------------------------------------------------------------------------": "",
1819
"build": "cross-env CLIENT_ENV=production craco build",
20+
"predeploy": "npm run build",
21+
"deploy": "gh-pages -d build",
1922
"---------- TESTING -------------------------------------------------------------------------------------": "",
2023
"test": "cross-env CLIENT_ENV=test craco test",
2124
"type-check": "tsc --noEmit",
@@ -42,12 +45,12 @@
4245
"axios": "0.19.0",
4346
"classnames": "2.2.6",
4447
"connected-react-router": "6.5.2",
45-
"dayjs": "1.8.16",
48+
"dayjs": "1.8.17",
4649
"history": "4.10.1",
4750
"lodash.groupby": "4.6.0",
4851
"react": "16.11.0",
4952
"react-dom": "16.11.0",
50-
"react-redux": "7.1.1",
53+
"react-redux": "7.1.3",
5154
"react-router-dom": "5.1.2",
5255
"redux": "4.0.4",
5356
"redux-devtools-extension": "2.13.8",
@@ -57,33 +60,35 @@
5760
"semantic-ui-css": "2.4.1",
5861
"semantic-ui-react": "0.88.1",
5962
"sjs-base-model": "1.9.0",
60-
"ts-optchain": "0.1.8",
6163
"uuid": "3.3.3"
6264
},
6365
"devDependencies": {
66+
"@babel/plugin-proposal-nullish-coalescing-operator": "7.4.4",
67+
"@babel/plugin-proposal-optional-chaining": "7.6.0",
6468
"@craco/craco": "5.6.1",
6569
"@types/classnames": "2.2.9",
6670
"@types/history": "4.7.3",
67-
"@types/jest": "24.0.21",
68-
"@types/node": "12.12.5",
71+
"@types/jest": "24.0.22",
72+
"@types/node": "12.12.7",
6973
"@types/react": "16.9.11",
70-
"@types/react-dom": "16.9.3",
74+
"@types/react-dom": "16.9.4",
7175
"@types/react-redux": "7.1.5",
7276
"@types/react-router-dom": "5.1.2",
7377
"@types/uuid": "3.4.6",
74-
"@typescript-eslint/eslint-plugin": "2.6.1",
75-
"@typescript-eslint/parser": "2.6.1",
78+
"@typescript-eslint/eslint-plugin": "2.7.0",
79+
"@typescript-eslint/parser": "2.7.0",
7680
"cross-env": "6.0.3",
7781
"eslint": "6.6.0",
7882
"eslint-config-prettier": "6.5.0",
7983
"eslint-plugin-prettier": "3.1.1",
8084
"eslint-plugin-react": "7.16.0",
8185
"generate-template-files": "2.2.0",
86+
"gh-pages": "2.1.1",
8287
"husky": "3.0.9",
8388
"node-sass": "4.13.0",
84-
"prettier": "1.18.2",
85-
"pretty-quick": "2.0.0",
89+
"prettier": "1.19.1",
90+
"pretty-quick": "2.0.1",
8691
"react-scripts": "3.2.0",
87-
"typescript": "3.6.4"
92+
"typescript": "3.7.2"
8893
}
8994
}

src/utilities/HttpUtility.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import axios from 'axios';
22
import HttpErrorResponseModel from '../models/HttpErrorResponseModel';
3-
import { oc } from 'ts-optchain';
43

54
const RequestMethod = {
65
Get: 'GET',
@@ -71,7 +70,7 @@ export default class HttpUtility {
7170
url: restRequest.url,
7271
headers: {
7372
'Content-Type': 'application/x-www-form-urlencoded',
74-
...oc(config).headers(undefined),
73+
...config?.headers,
7574
},
7675
};
7776

src/views/home-page/components/actors/components/ActorCard.jsx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,16 @@
11
import React from 'react';
22
import { Card, Image } from 'semantic-ui-react';
3-
import { oc } from 'ts-optchain';
43

54
export default class ActorCard extends React.PureComponent {
65
render() {
76
const { cardData } = this.props;
8-
const image = oc(cardData).character.image.medium('');
7+
const image = cardData?.character?.image?.medium;
98
const missingImage = 'https://react.semantic-ui.com/images/wireframe/image.png';
109

1110
return (
1211
<Card key={cardData.person.name}>
1312
<Card.Content>
14-
<Image floated="right" size="mini" src={image || missingImage} />
13+
<Image floated="right" size="mini" src={image ?? missingImage} />
1514
<Card.Header>{cardData.person.name}</Card.Header>
1615
<Card.Meta>as {cardData.character.name}</Card.Meta>
1716
<Card.Description>

src/views/home-page/components/main-overview/MainOverview.jsx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import React from 'react';
22
import { connect } from 'react-redux';
33
import { Item } from 'semantic-ui-react';
4-
import { oc } from 'ts-optchain';
54
import ShowsAction from '../../../../stores/shows/ShowsAction';
65

76
const mapStateToProps = (state, ownProps) => ({
@@ -20,8 +19,8 @@ class MainOverview extends React.Component {
2019
return null;
2120
}
2221

23-
const image = oc(show).image.medium('');
24-
const network = oc(show).network.name('');
22+
const image = show?.image?.medium ?? '';
23+
const network = show?.network?.name ?? '';
2524

2625
return (
2726
<Item.Group>

0 commit comments

Comments
 (0)