Skip to content

Commit e732b43

Browse files
authored
Updated playground project and added integration with react-redux-typescript-scripts (#156)
Resolved #69
1 parent 34fc808 commit e732b43

12 files changed

+5130
-15593
lines changed

README.md

+72-133
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ _"This guide is a **living compendium** documenting the most important patterns
1717
### Complementary Libraries
1818
- [utility-types](https://github.com/piotrwitek/utility-types) - Collection of generic types for TypeScript, complementing built-in mapped types and aliases - think lodash for reusable types.
1919
- [typesafe-actions](https://github.com/piotrwitek/typesafe-actions) - Typesafe utilities for "action-creators" in Redux / Flux Architecture
20+
- [react-redux-typescript-scripts](https://github.com/piotrwitek/react-redux-typescript-scripts) - dev-tools configuration files shared between projects based on this guide
2021

2122
### Playground Project
2223
[![Build Status](https://semaphoreci.com/api/v1/piotrekwitek/react-redux-typescript-guide/branches/master/shields_badge.svg)](https://semaphoreci.com/piotrekwitek/react-redux-typescript-guide)
@@ -63,13 +64,14 @@ Issues can be funded by anyone and the money will be transparently distributed t
6364
- [Async Flow with `redux-thunk`](#async-flow-with-redux-thunk) 🌟 __NEW__
6465
- [Selectors with `reselect`](#selectors-with-reselect)
6566
- [Connect with `react-redux`](#connect-with-react-redux) 🌟 __NEW__
66-
- [Tools](#tools)
67+
- [Configuration & Dev Tools](#configuration-&-dev-tools)
68+
- [Common Npm Scripts](#common-npm-scripts)
69+
- [TypeScript](#typescript)
70+
- [TSLib](#tslib)
6771
- [TSLint](#tslint)
6872
- [Jest](#jest)
69-
- [Living Style Guide](#living-style-guide)
70-
- [Common Npm Scripts](#common-npm-scripts)
73+
- [Style Guide](#style-guide)
7174
- [Recipes](#recipes)
72-
- [Baseline tsconfig.json](#baseline-tsconfigjson)
7375
- [General Tips](#general-tips)
7476
- [Ambient Modules Tips](#ambient-modules-tips)
7577
- [Type-Definitions Tips](#type-definitions-tips)
@@ -492,7 +494,7 @@ export const withState = <BaseProps extends InjectedProps>(
492494
};
493495

494496
render() {
495-
const { ...restProps } = this.props as any;
497+
const { ...restProps } = this.props as {};
496498
const { count } = this.state;
497499

498500
return (
@@ -1488,80 +1490,81 @@ type DispatchProps = ReturnType<typeof mapDispatchToProps>;
14881490
14891491
---
14901492
1491-
# Tools
1493+
# Configuration & Dev Tools
1494+
1495+
## Common Npm Scripts
1496+
> Common TS-related npm scripts shared across projects
1497+
```
1498+
"ci-check": "npm run lint && npm run tsc && npm run test",
1499+
"lint": "tslint -p ./",
1500+
"tsc": "tsc -p ./ --noEmit",
1501+
"tsc:watch": "tsc -p ./ --noEmit -w",
1502+
"test": "jest --config jest.config.json",
1503+
"test:watch": "jest --config jest.config.json --watch",
1504+
"test:update": "jest --config jest.config.json -u"
1505+
```
1506+
1507+
[⇧ back to top](#table-of-contents)
1508+
1509+
### TypeScript
1510+
1511+
We have our own recommended `tsconfig.json` that you can easily add to your project thanks to [`react-redux-typescript-scripts`](https://github.com/piotrwitek/react-redux-typescript-scripts) package.
1512+
1513+
#### tsconfig.json
1514+
<details><summary><i>Click to expand</i></summary><p>
1515+
1516+
```tsx
1517+
{
1518+
"include": ["src", "typings"],
1519+
"extends": "./node_modules/react-redux-typescript-scripts/tsconfig.json",
1520+
"compilerOptions": {
1521+
// you can further customize options here
1522+
}
1523+
}
1524+
1525+
```
1526+
</p></details>
1527+
1528+
[⇧ back to top](#table-of-contents)
1529+
1530+
## TSLib
1531+
https://www.npmjs.com/package/tslib
1532+
1533+
This library will cut down on your bundle size, thanks to using external runtime helpers instead of adding them per each file.
1534+
1535+
> Installation
1536+
`npm i tslib`
1537+
1538+
Then add this to your `tsconfig.json`:
1539+
```ts
1540+
"compilerOptions": {
1541+
"importHelpers": true
1542+
}
1543+
```
1544+
1545+
[⇧ back to top](#table-of-contents)
14921546
14931547
## TSLint
1548+
https://palantir.github.io/tslint/
14941549
14951550
> Installation
14961551
`npm i -D tslint`
14971552
1498-
#### tslint.json
1499-
- Recommended setup is to extend build-in preset `tslint:recommended` (use `tslint:all` to enable all rules)
1500-
- Add additional `react` specific rules: `npm i -D tslint-react` https://github.com/palantir/tslint-react
1501-
- Overwritten some defaults for more flexibility
1553+
> For React project you should add additional `react` specific rules: `npm i -D tslint-react` https://github.com/palantir/tslint-react
1554+
1555+
We have our own recommended config that you can easily add to your project thanks to [`react-redux-typescript-scripts`](https://github.com/piotrwitek/react-redux-typescript-scripts) package.
15021556
1557+
#### tslint.json
15031558
<details><summary><i>Click to expand</i></summary><p>
15041559
15051560
```tsx
15061561
{
1507-
"extends": ["tslint:recommended", "tslint-react"],
1562+
"extends": [
1563+
"react-redux-typescript-scripts/tslint-recommended.json",
1564+
"react-redux-typescript-scripts/tslint-react.json"
1565+
],
15081566
"rules": {
1509-
"arrow-parens": false,
1510-
"arrow-return-shorthand": [false],
1511-
"comment-format": [true, "check-space"],
1512-
"import-blacklist": [true],
1513-
"interface-over-type-literal": false,
1514-
"interface-name": false,
1515-
"max-line-length": [true, 120],
1516-
"member-access": false,
1517-
"member-ordering": [true, { "order": "fields-first" }],
1518-
"newline-before-return": false,
1519-
"no-any": false,
1520-
"no-empty-interface": false,
1521-
"no-import-side-effect": [true],
1522-
"no-inferrable-types": [true, "ignore-params", "ignore-properties"],
1523-
"no-invalid-this": [true, "check-function-in-method"],
1524-
"no-namespace": false,
1525-
"no-null-keyword": false,
1526-
"no-require-imports": false,
1527-
"no-submodule-imports": [true, "@src", "rxjs"],
1528-
"no-this-assignment": [true, { "allow-destructuring": true }],
1529-
"no-trailing-whitespace": true,
1530-
"object-literal-sort-keys": false,
1531-
"object-literal-shorthand": false,
1532-
"one-variable-per-declaration": [false],
1533-
"only-arrow-functions": [true, "allow-declarations"],
1534-
"ordered-imports": [false],
1535-
"prefer-method-signature": false,
1536-
"prefer-template": [true, "allow-single-concat"],
1537-
"quotemark": [true, "single", "jsx-double"],
1538-
"semicolon": [true, "always", "ignore-bound-class-methods"],
1539-
"trailing-comma": [
1540-
true,
1541-
{
1542-
"singleline": "never",
1543-
"multiline": {
1544-
"objects": "always",
1545-
"arrays": "always",
1546-
"functions": "ignore",
1547-
"typeLiterals": "ignore"
1548-
},
1549-
"esSpecCompliant": true
1550-
}
1551-
],
1552-
"triple-equals": [true, "allow-null-check"],
1553-
"type-literal-delimiter": true,
1554-
"typedef": [true, "parameter", "property-declaration"],
1555-
"variable-name": [
1556-
true,
1557-
"ban-keywords",
1558-
"check-format",
1559-
"allow-pascal-case",
1560-
"allow-leading-underscore"
1561-
],
1562-
// tslint-react
1563-
"jsx-no-multiline-js": false,
1564-
"jsx-no-lambda": false
1567+
// you can further customize options here
15651568
}
15661569
}
15671570

@@ -1571,6 +1574,7 @@ type DispatchProps = ReturnType<typeof mapDispatchToProps>;
15711574
[⇧ back to top](#table-of-contents)
15721575
15731576
## Jest
1577+
https://jestjs.io/
15741578
15751579
> Installation
15761580
`npm i -D jest ts-jest @types/jest`
@@ -1631,7 +1635,7 @@ Object.values = () => [];
16311635
16321636
[⇧ back to top](#table-of-contents)
16331637
1634-
## Living Style Guide
1638+
## Style Guide
16351639
### ["react-styleguidist"](https://github.com/styleguidist/react-styleguidist)
16361640
16371641
[⟩⟩⟩ styleguide.config.js](/playground/styleguide.config.js)
@@ -1640,75 +1644,10 @@ Object.values = () => [];
16401644
16411645
[⇧ back to top](#table-of-contents)
16421646
1643-
## Common Npm Scripts
1644-
> Common TS-related npm scripts shared across projects
1645-
```
1646-
"lint": "tslint -p ./",
1647-
"tsc": "tsc -p ./ --noEmit",
1648-
"tsc:watch": "tsc -p ./ --noEmit -w",
1649-
"pretest": "npm run lint & npm run tsc",
1650-
"test": "jest --config jest.config.json",
1651-
"test:watch": "jest --config jest.config.json --watch",
1652-
"test:update": "jest --config jest.config.json -u",
1653-
```
1654-
1655-
[⇧ back to top](#table-of-contents)
1656-
16571647
---
16581648
16591649
# Recipes
16601650
1661-
### Baseline tsconfig.json
1662-
1663-
- Recommended baseline config carefully optimized for strict type-checking and optimal webpack workflow
1664-
- Install [`tslib`](https://www.npmjs.com/package/tslib) to cut on bundle size, by using external runtime helpers instead of adding them inline: `npm i tslib`
1665-
- Example "paths" setup for baseUrl relative imports with Webpack
1666-
1667-
<details><summary><i>Click to expand</i></summary><p>
1668-
1669-
```tsx
1670-
{
1671-
"compilerOptions": {
1672-
"baseUrl": "./", // relative paths base
1673-
"paths": {
1674-
// "@src/*": ["src/*"] // will enable import aliases -> import { ... } from '@src/components'
1675-
// WARNING: Require to add this to your webpack config -> resolve: { alias: { '@src': PATH_TO_SRC } }
1676-
// "redux": ["typings/redux"], // override library types with your alternative type-definitions in typings folder
1677-
"redux-thunk": ["typings/redux-thunk"] // override library types with your alternative type-definitions in typings folder
1678-
},
1679-
"outDir": "dist/", // target for compiled files
1680-
"allowSyntheticDefaultImports": true, // no errors with commonjs modules interop
1681-
"esModuleInterop": true, // enable to do "import React ..." instead of "import * as React ..."
1682-
"allowJs": true, // include js files
1683-
"checkJs": true, // typecheck js files
1684-
"declaration": false, // don't emit declarations
1685-
"emitDecoratorMetadata": true, // include only if using decorators
1686-
"experimentalDecorators": true, // include only if using decorators
1687-
"forceConsistentCasingInFileNames": true,
1688-
"importHelpers": true, // importing transpilation helpers from tslib
1689-
"noEmitHelpers": true, // disable inline transpilation helpers in each file
1690-
"jsx": "react", // transform JSX
1691-
"lib": ["dom", "es2017"], // you will need to include polyfills for es2017 manually
1692-
"types": ["jest"], // which global types to use
1693-
"target": "es5", // "es2015" for ES6+ engines
1694-
"module": "es2015", // "es2015" for tree-shaking
1695-
"moduleResolution": "node",
1696-
"noEmitOnError": true,
1697-
"noFallthroughCasesInSwitch": true,
1698-
"noUnusedLocals": true,
1699-
"strict": true,
1700-
"pretty": true,
1701-
"removeComments": true,
1702-
"sourceMap": true
1703-
},
1704-
"include": ["src", "typings"]
1705-
}
1706-
1707-
```
1708-
</p></details>
1709-
1710-
[⇧ back to top](#table-of-contents)
1711-
17121651
### General Tips
17131652
17141653
#### - should I still use React.PropTypes in TS?

0 commit comments

Comments
 (0)