Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
bdec1e5
Updated tests to fix build Closed #95 (#133)
piotrwitek Feb 3, 2019
857d9fd
Adds info import module decleration (#134)
arshadkazmi42 Feb 4, 2019
23ffca5
Updated Recipes section Closed #137
piotrwitek Feb 12, 2019
8f51601
Updated TOC
piotrwitek Feb 12, 2019
af7d940
Updated deps (#139)
piotrwitek Feb 12, 2019
c06d37a
Added example for using context in class component (#141)
binoy14 Feb 14, 2019
33d96b6
Testing epics (#144)
piotrwitek Feb 22, 2019
8c796de
updated deps
piotrwitek Mar 7, 2019
1259b21
added redux-thunk types overload
piotrwitek Mar 7, 2019
d0a05b2
Updated legacy patterns
piotrwitek Mar 7, 2019
5d03b97
ThunkActionType prototype
piotrwitek Mar 7, 2019
342a6ad
fix spelling mistake (#152)
SCKelemen Apr 6, 2019
0ecf245
Updated docs and and example of integration with redux-thunk Resolved…
piotrwitek Apr 6, 2019
c8d35fe
Merge branch 'redux-thunk'
piotrwitek Apr 6, 2019
b5cefb4
Added hyperlinks for better UX
piotrwitek Apr 6, 2019
34fc808
Small updates
piotrwitek Apr 13, 2019
e732b43
Updated playground project and added integration with react-redux-typ…
piotrwitek Apr 13, 2019
3f978be
Added new solution to Connect with `react-redux` to solve validation …
piotrwitek Apr 13, 2019
acd9b20
Added ESLint config section (#158)
piotrwitek Apr 14, 2019
93fc2b8
Refactored playground to use create-react-app (#159)
piotrwitek Apr 14, 2019
cf8a03c
Capitalize file to fix import on POSIX systems (#160)
lordi Apr 15, 2019
05ddc8f
Added prettier to common npm scripts
piotrwitek Apr 18, 2019
0ff885d
Added doctoc
piotrwitek Apr 21, 2019
01bc1df
Updated readme
piotrwitek Apr 21, 2019
0c2afc9
Updated readme with new section about createReducer API
piotrwitek Apr 22, 2019
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Updated playground project and added integration with react-redux-typ…
…escript-scripts (piotrwitek#156)

Resolved piotrwitek#69
  • Loading branch information
piotrwitek authored Apr 13, 2019
commit e732b43de982f65dade41d896b9a2a3ff703d4e7
205 changes: 72 additions & 133 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ _"This guide is a **living compendium** documenting the most important patterns
### Complementary Libraries
- [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.
- [typesafe-actions](https://github.com/piotrwitek/typesafe-actions) - Typesafe utilities for "action-creators" in Redux / Flux Architecture
- [react-redux-typescript-scripts](https://github.com/piotrwitek/react-redux-typescript-scripts) - dev-tools configuration files shared between projects based on this guide

### Playground Project
[![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)
Expand Down Expand Up @@ -63,13 +64,14 @@ Issues can be funded by anyone and the money will be transparently distributed t
- [Async Flow with `redux-thunk`](#async-flow-with-redux-thunk) 🌟 __NEW__
- [Selectors with `reselect`](#selectors-with-reselect)
- [Connect with `react-redux`](#connect-with-react-redux) 🌟 __NEW__
- [Tools](#tools)
- [Configuration & Dev Tools](#configuration-&-dev-tools)
- [Common Npm Scripts](#common-npm-scripts)
- [TypeScript](#typescript)
- [TSLib](#tslib)
- [TSLint](#tslint)
- [Jest](#jest)
- [Living Style Guide](#living-style-guide)
- [Common Npm Scripts](#common-npm-scripts)
- [Style Guide](#style-guide)
- [Recipes](#recipes)
- [Baseline tsconfig.json](#baseline-tsconfigjson)
- [General Tips](#general-tips)
- [Ambient Modules Tips](#ambient-modules-tips)
- [Type-Definitions Tips](#type-definitions-tips)
Expand Down Expand Up @@ -492,7 +494,7 @@ export const withState = <BaseProps extends InjectedProps>(
};

render() {
const { ...restProps } = this.props as any;
const { ...restProps } = this.props as {};
const { count } = this.state;

return (
Expand Down Expand Up @@ -1488,80 +1490,81 @@ type DispatchProps = ReturnType<typeof mapDispatchToProps>;

---

# Tools
# Configuration & Dev Tools

## Common Npm Scripts
> Common TS-related npm scripts shared across projects
```
"ci-check": "npm run lint && npm run tsc && npm run test",
"lint": "tslint -p ./",
"tsc": "tsc -p ./ --noEmit",
"tsc:watch": "tsc -p ./ --noEmit -w",
"test": "jest --config jest.config.json",
"test:watch": "jest --config jest.config.json --watch",
"test:update": "jest --config jest.config.json -u"
```

[⇧ back to top](#table-of-contents)

### TypeScript

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.

#### tsconfig.json
<details><summary><i>Click to expand</i></summary><p>

```tsx
{
"include": ["src", "typings"],
"extends": "./node_modules/react-redux-typescript-scripts/tsconfig.json",
"compilerOptions": {
// you can further customize options here
}
}

```
</p></details>

[⇧ back to top](#table-of-contents)

## TSLib
https://www.npmjs.com/package/tslib

This library will cut down on your bundle size, thanks to using external runtime helpers instead of adding them per each file.

> Installation
`npm i tslib`

Then add this to your `tsconfig.json`:
```ts
"compilerOptions": {
"importHelpers": true
}
```

[⇧ back to top](#table-of-contents)

## TSLint
https://palantir.github.io/tslint/

> Installation
`npm i -D tslint`

#### tslint.json
- Recommended setup is to extend build-in preset `tslint:recommended` (use `tslint:all` to enable all rules)
- Add additional `react` specific rules: `npm i -D tslint-react` https://github.com/palantir/tslint-react
- Overwritten some defaults for more flexibility
> For React project you should add additional `react` specific rules: `npm i -D tslint-react` https://github.com/palantir/tslint-react

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.

#### tslint.json
<details><summary><i>Click to expand</i></summary><p>

```tsx
{
"extends": ["tslint:recommended", "tslint-react"],
"extends": [
"react-redux-typescript-scripts/tslint-recommended.json",
"react-redux-typescript-scripts/tslint-react.json"
],
"rules": {
"arrow-parens": false,
"arrow-return-shorthand": [false],
"comment-format": [true, "check-space"],
"import-blacklist": [true],
"interface-over-type-literal": false,
"interface-name": false,
"max-line-length": [true, 120],
"member-access": false,
"member-ordering": [true, { "order": "fields-first" }],
"newline-before-return": false,
"no-any": false,
"no-empty-interface": false,
"no-import-side-effect": [true],
"no-inferrable-types": [true, "ignore-params", "ignore-properties"],
"no-invalid-this": [true, "check-function-in-method"],
"no-namespace": false,
"no-null-keyword": false,
"no-require-imports": false,
"no-submodule-imports": [true, "@src", "rxjs"],
"no-this-assignment": [true, { "allow-destructuring": true }],
"no-trailing-whitespace": true,
"object-literal-sort-keys": false,
"object-literal-shorthand": false,
"one-variable-per-declaration": [false],
"only-arrow-functions": [true, "allow-declarations"],
"ordered-imports": [false],
"prefer-method-signature": false,
"prefer-template": [true, "allow-single-concat"],
"quotemark": [true, "single", "jsx-double"],
"semicolon": [true, "always", "ignore-bound-class-methods"],
"trailing-comma": [
true,
{
"singleline": "never",
"multiline": {
"objects": "always",
"arrays": "always",
"functions": "ignore",
"typeLiterals": "ignore"
},
"esSpecCompliant": true
}
],
"triple-equals": [true, "allow-null-check"],
"type-literal-delimiter": true,
"typedef": [true, "parameter", "property-declaration"],
"variable-name": [
true,
"ban-keywords",
"check-format",
"allow-pascal-case",
"allow-leading-underscore"
],
// tslint-react
"jsx-no-multiline-js": false,
"jsx-no-lambda": false
// you can further customize options here
}
}

Expand All @@ -1571,6 +1574,7 @@ type DispatchProps = ReturnType<typeof mapDispatchToProps>;
[⇧ back to top](#table-of-contents)

## Jest
https://jestjs.io/

> Installation
`npm i -D jest ts-jest @types/jest`
Expand Down Expand Up @@ -1631,7 +1635,7 @@ Object.values = () => [];

[⇧ back to top](#table-of-contents)

## Living Style Guide
## Style Guide
### ["react-styleguidist"](https://github.com/styleguidist/react-styleguidist)

[⟩⟩⟩ styleguide.config.js](/playground/styleguide.config.js)
Expand All @@ -1640,75 +1644,10 @@ Object.values = () => [];

[⇧ back to top](#table-of-contents)

## Common Npm Scripts
> Common TS-related npm scripts shared across projects
```
"lint": "tslint -p ./",
"tsc": "tsc -p ./ --noEmit",
"tsc:watch": "tsc -p ./ --noEmit -w",
"pretest": "npm run lint & npm run tsc",
"test": "jest --config jest.config.json",
"test:watch": "jest --config jest.config.json --watch",
"test:update": "jest --config jest.config.json -u",
```

[⇧ back to top](#table-of-contents)

---

# Recipes

### Baseline tsconfig.json

- Recommended baseline config carefully optimized for strict type-checking and optimal webpack workflow
- 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`
- Example "paths" setup for baseUrl relative imports with Webpack

<details><summary><i>Click to expand</i></summary><p>

```tsx
{
"compilerOptions": {
"baseUrl": "./", // relative paths base
"paths": {
// "@src/*": ["src/*"] // will enable import aliases -> import { ... } from '@src/components'
// WARNING: Require to add this to your webpack config -> resolve: { alias: { '@src': PATH_TO_SRC } }
// "redux": ["typings/redux"], // override library types with your alternative type-definitions in typings folder
"redux-thunk": ["typings/redux-thunk"] // override library types with your alternative type-definitions in typings folder
},
"outDir": "dist/", // target for compiled files
"allowSyntheticDefaultImports": true, // no errors with commonjs modules interop
"esModuleInterop": true, // enable to do "import React ..." instead of "import * as React ..."
"allowJs": true, // include js files
"checkJs": true, // typecheck js files
"declaration": false, // don't emit declarations
"emitDecoratorMetadata": true, // include only if using decorators
"experimentalDecorators": true, // include only if using decorators
"forceConsistentCasingInFileNames": true,
"importHelpers": true, // importing transpilation helpers from tslib
"noEmitHelpers": true, // disable inline transpilation helpers in each file
"jsx": "react", // transform JSX
"lib": ["dom", "es2017"], // you will need to include polyfills for es2017 manually
"types": ["jest"], // which global types to use
"target": "es5", // "es2015" for ES6+ engines
"module": "es2015", // "es2015" for tree-shaking
"moduleResolution": "node",
"noEmitOnError": true,
"noFallthroughCasesInSwitch": true,
"noUnusedLocals": true,
"strict": true,
"pretty": true,
"removeComments": true,
"sourceMap": true
},
"include": ["src", "typings"]
}

```
</p></details>

[⇧ back to top](#table-of-contents)

### General Tips

#### - should I still use React.PropTypes in TS?
Expand Down
Loading